C++ 38: Visibility Modes Public, Private and Protected

 Visibility Modes and Access specifier: 


class Derived: public | private | protected BaseClass <----- Visibility Modes
{
    private:   <------ Access Specifier
            int A;
    public:    <------ Access Specifier
            int B;
    protected:    <------ Access Specifier
            int C;
};

  • Visibility modes decides the accessiblity of the base class members in derived class.
  • The visibility mode can be Private, Public, Protected.
  • While deriving new class, if the visibility mode is not specified then by default it is private.


Visibility Modes:

private: If a base class is inherited as private in a derived class then all the public and protected member of the base class becomes the private in derived class.

protected: If the base class inherited as protected in the derived class then all the public and protected members of the base class becomes the protected in derived class.

public: If a base class is inherited as public in derived class then all the public members remains public and all the protected members remains protected in derived class.














Comments