Asked by: Nurul Larrazatechnology and computing programming languages
Can objects of a class access protected members?
Last Updated: 27th February, 2020
Click to see full answer.
Simply so, can objects access protected members?
Protected members (C++ only) A protected nonstatic base class member can be accessed by members and friends of any classes derived from that base class by using one of the following: An object of a directly or indirectly derived class.
Similarly, what is a protected class member? Protected members are accessible in the class that defines them and in classes that inherit from that class. Edit: Both are also accessible by friends of their class, and in the case of protected members, by friends of their derived classes.
Subsequently, question is, how can a protected member can be accessed?
Protected data member and method are only accessible by the classes of the same package and the subclasses present in any package. You can also say that the protected access modifier is similar to default access modifier with one exception that it has visibility in sub classes. Classes cannot be declared protected.
Are protected members inherited?
Its only difference occurs in fact with inheritance: When a class inherits another one, the members of the derived class can access the protected members inherited from the base class, but not its private members. With protected , all public members of the base class are inherited as protected in the derived class.