Public visibility | Protected visibility |
The public derivation means that the derived class can access the public and protected members of the base class but not the private members of the base class. | The protected derivation means that the derived class can access the public and private members of the base class protectedly. |
With publicly derived class, the public members of the base class become the public members of the derived class, and the protected members of the base class become the protected members of the derived class. | With protectedly derived class, the public and protected members of the base class become protected members of the derived class. |
Example: class super { private: int x; void get(); public: int y; void put(); protected: int z; void disp(); }; class sub:public super { private: int a; void init(); public: int b; void readit(); protected: int c; void writeit(); }; | Example: class super { private: int x; void get(); public: int y; void put(); protected: int z; void disp(); }; class sub:protected super { private: int a; void init();
public: int b; void readit(); protected: int c; void writeit(); }; |