answersLogoWhite

0


Best Answer

False. Public member data is accessible to all functions, whether they be public, protected or private members of the same class, or they are outside of the class completely.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Only public member functions can access public member data TrueFalse?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What are different ways by which you can access public member functions of an object?

You simply access it. That's what public means. You can access a public member from any other class, or even from non class code, so long as the referenced class is in scope to the referencing code. In order to do that, you need to have a reference (directly or indirectly) to the instance of the class you want to reference. This would generally be passed as an argument to the referencing code.


What kinds of access can a class member have?

Public, protected and private access members.


How can you access private functions of a class from the Main function in Cpp?

Any member functions and data members declared as 'private' in a class, can only be accessed directly by functions within the class.They cannot be accessed directly by derived objects, nor from anywhere outside an object of the class, such as from the Main function.To access private class members, you must rely on what are called accessor functions. Accessor functions are functions inside the class, either public or protected, which automatically have access to private members.If a function from Main, or elsewhere outside the class hierarchy, needs access, then you need to use publicaccessor functions. For derived class access, you can use protected accessor functions.


What in Online Public Access catalog functions?

to provide the library with more information


Which base class member functions are not inherited by a derived class?

Derived classes only inherit the protected and public members of their base classes. Private member functions cannot be inherited by a derived class.

Related questions

What are different ways by which you can access public member functions of an object?

You simply access it. That's what public means. You can access a public member from any other class, or even from non class code, so long as the referenced class is in scope to the referencing code. In order to do that, you need to have a reference (directly or indirectly) to the instance of the class you want to reference. This would generally be passed as an argument to the referencing code.


What do you mean by access specifier in c?

There are no access specifiers in C. All functions and data are public.


What kinds of access can a class member have?

Public, protected and private access members.


What in Online Public Access catalog functions?

to provide the library with more information


How can you access private functions of a class from the Main function in Cpp?

Any member functions and data members declared as 'private' in a class, can only be accessed directly by functions within the class.They cannot be accessed directly by derived objects, nor from anywhere outside an object of the class, such as from the Main function.To access private class members, you must rely on what are called accessor functions. Accessor functions are functions inside the class, either public or protected, which automatically have access to private members.If a function from Main, or elsewhere outside the class hierarchy, needs access, then you need to use publicaccessor functions. For derived class access, you can use protected accessor functions.


Which base class member functions are not inherited by a derived class?

Derived classes only inherit the protected and public members of their base classes. Private member functions cannot be inherited by a derived class.


What does In public mean?

The keyword public is an access specifier. A variable or a method that is declared public is publicly accessible to any member of the project. Any class or method can freely access other public methods and variables of another class.


Difference friend and public access modifier?

In C++, a friend function or friend class can grant access to its private data members to other classes. The public member allows any class to access that data.


When do you use the protected access specifier on a class member in c plus plus?

You use the protected access specifier to allow a derived class implementer access to what would otherwise be a private member method of your class. Private member methods are intended for internal use only, however some may be optimised versions of public member functions. Public member functions, particularly accessors (getters) and mutators (setters), often contain additional runtime checks that are usually redundant to the internal implementation. While we may not wish to allow "ordinary" users access to these optimised functions, derived class implementers are not ordinary users. Like you (the class designer) they want to create an efficient implementation and would therefore benefit from having access to your private implementations, or at least some of them. We achieve this by declaring those methods protected. Note that although you can also allow class implementers protected access to your otherwise private member data, this is not recommended as class implementers would then be able to undermine your data encapsulation. Class representations must remain private to maintain encapsulation. Similarly, any private methods that have potential for undermining encapsulation should likewise remain private.


What are the Functions of public communication?

Functions of public communication


What is meant by public facilities?

Public facility means that anybody can use it - e.g. a public restroom/toilet, public phone, public park, etc. You don't need to be a member or someone special to get access.


What is classes in programing?

There are no classes in C; it is not an object-oriented programming language. C++ has classes. A class is a data type from which objects can instantiated in much the same way that an integer variable can be instantiated from an int data type in both C and C++. However, an int is a primitive data type; it has no member methods associated with it. The built-in operators are designed to operate upon primitive data types but those operators are not integral to the type. A class is more like a struct in C; an aggregate of data values. A class can contain both static data (data that is common to the class) and non-static data (data that relates to an instance of the class). However, as well as storing data, a class can also define member functions that operate upon that data, but that are scoped to the class (static member functions) or to an instance of the class (instance member functions). Unlike C where a struct's data members are always public, a C++ class can define separate public, protected and private data members (and functions), where private is the default access. A C++ struct is also a class, but one where the members are public by default. As such, a C++ struct can be used to create trivial "plain old data" classes that are compatible with C code as well as to create highly complex data types. Objects are self-contained entities where the member methods (functions and operators) have private access to the class representation. Non-member functions cannot gain access to this representation other than through public member functions or by being declared a friend of the class. The protected representation is the same as the private representation but is also accessible to derivatives of the class. Derivatives automatically inherit the public and protected members of their base classes, but not the private members. This makes it possible to derive more specialised classes from existing classes without have to duplicate the base class code.