Programming with Passion

Make the best out of everything.

Saturday, 26 March 2016

Keyword protected

Keyword protected

In this program, length and breadth in the base class are protected data members. These data members are accessible from the derived class but, not accessible from outside it. This maintains the feature of data hiding in C++ programming. If you defined length and breadth as private members then, those two data are not accessible to derived class and if defined as public members, it can be accessible from both derived class and from main( ) function.
Accessbilityprivateprotectedpublic
Accessible from own class ?yesyesyes
Accessible from dervied class ?noyesyes
Accessible outside dervied class ?nonoyes

Member Function Overriding in Inheritance

Suppose, base class and derived class have member functions with same name and arguments. If you create an object of derived class and write code to access that member function then, the member function in derived class is only invoked, i.e., the member function of derived class overrides the member function of base class.

No comments:

Post a Comment