class will be inherited as protected members of the derived class and the public members of the base class will be inherited as public members of the derived class. BASE CLASS when inherited with public visibility become become DERIVED CLASS private members private members protected members protected members public members public members Tip Notes When classes are inherited with public, protected or private the private members of the base class are not inherited they are only visible i.e continue to exist in derived classes, and cannot be accessed //Implementation of Single Inheritance using public visibility mode #include <iostream> using namespace std; class Shape { private: int count; protected: int width, height; public: void setWidth(int w) width = w; } void setHeight(int h) { height = h; } }; Illustration . Explains the significance of different visibility modes. Chapter Page - - class Rectangle: public Shape public: int getArea() return (width * height); }; int main() Rectangle Rect; Rect.setWidth( ); Rect.setHeight( ); // Print the area of theobject.
cout<< "Total area: "<<Rect.getArea() <<endl; return ; Output Total area: The following table contain the members defined inside each class before inheritance MEMBERS of class visibility modes Private Protected Public Shape(base class) int count; int width; int height; void setWidth(int ) void setHeight(int) Rectangle (derived class only with its defined members) int getArea(); The following table contains the details of members defined after inheritance MEMBERS of class visibility modes –public for acquiring the properties of the base class Private Protected Public Shape(base class) int count; int width; int height; void setWidth(int ) void setHeight(int) Rectangle (derived class acquired the properties of base class with public visibility) Private members of base classes are not directly accessible by the derived class int width; int height; int getArea(); void setWidth(int ) void setHeight(int) Suppose the class rectangle is derived with protected visibility then the properties of class rectangle will change as follows Chapter Page - - MEMBERS of class visibility modes –protected for acquiring the properties of the base class Private Protected Public Shape(base class) int count; int width;