answersLogoWhite

0


Best Answer

Use the class member access operators. For object references, use the . operator, for pointers, use the -> operator.

class obj

{

public:

void foo(){}

};

void main()

{

obj o, *p=&o;

o.foo(); // Access member via reference.

p->foo(); // Access member via pointer.

return( 0 );

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

You have to instantiate it, using the constructor. It should look something like this: Dog rex = new Dog(3, Color.BLACK); This is just an example

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

To create an object

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you access nembers of a class?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can a parent class access the functions of child class?

no, Parent class can not access the members of child class ,but child class can access members of parent class


What is mean by class access?

Class access is the ability for any given class to access the functions of another class. Private access limits access to data and code just to the class that contains the private access modifier. The so-called "default" access grants private access, as well as access to any class in the same package. Protected access grants the same as "default" access, and also allows subclasses to access the code and data. Public access allows any class in any package to access the code and data.


Can you access a protected member from a Sub class outside the package of its Base class?

Protected members of a class are only accessible to its subclasses and to friends of the class or its subclasses. However, if a subclass changes the access to private, only the subclass and its friends have access but this does not affect the access rights of its ancestors or their friends.


Is the default access specifier same as protected?

A private member of a class can only be accessed by methods of that class. A protected member of a class can only be accessed by methods of that class and by methods of a derived class of that class.


Which C plus plus keyword allows a function outside of a class to access private class members?

The keyword is friend. The external function must be declared a friend of the class (from within the class itself) in order to become a member of the class and thus gain access to the private (and protected) members of the class.

Related questions

What are the ranks of nembers of the Jewish Police Force in Palestine?

Noter


Can a parent class access the functions of child class?

no, Parent class can not access the members of child class ,but child class can access members of parent class


What is mean by class access?

Class access is the ability for any given class to access the functions of another class. Private access limits access to data and code just to the class that contains the private access modifier. The so-called "default" access grants private access, as well as access to any class in the same package. Protected access grants the same as "default" access, and also allows subclasses to access the code and data. Public access allows any class in any package to access the code and data.


What is the greatest factore that two or more nembers have in common?

one of those two numbers.


Who did he know that is still alive?

his wife died and he lived with his daughter and other family nembers


What is mean by accessibility?

Class access is the ability for any given class to access the functions of another class. Private access limits access to data and code just to the class that contains the private access modifier. The so-called "default" access grants private access, as well as access to any class in the same package. Protected access grants the same as "default" access, and also allows subclasses to access the code and data. Public access allows any class in any package to access the code and data.


How do you stroke Chevy 350 engine?

can i have apart nembers the the rebeld 350 engine to get ahi hp


What is the use of public access specifier?

use of public access specifier iswe can access the class members(methods,variables) out side the class using class reference


Can you access a protected member from a Sub class outside the package of its Base class?

Protected members of a class are only accessible to its subclasses and to friends of the class or its subclasses. However, if a subclass changes the access to private, only the subclass and its friends have access but this does not affect the access rights of its ancestors or their friends.


What is meant by default access of class in java?

That's what you get when you don't include any access specifier, such as "public" or "private". This default access gives access to any class in the same package.


Different access specifies in C plus plus?

Public members and methods of a class are universally accessible. Protected members and methods of a class are accessible to methods of instances of that class and its derived classes. Private members and methods of a class are accessible only to methods of instances of that class.Class A has three members: public_member, protected_member, and private_member, which have access corresponding to their names. Class A has access to all three. Class B, derived from class A, has access to public_member and protected_member, but not private_member. Unrelated class C has access only to public_member.


How the jvm is able to access your class even you declare it using default access specifier but the same class is not accessed from other class which is declared in another package?

The JVM knows about all of your classes, no matter what package they are in or what access specifier you declared them with. The access specifier is only used to limit access from other classes.