Visibility modes:
private
protected
public
Private:
o When a base class is privately inherited by a derived class, „public
members‟ and „protected members‟ of the base class become
„private members‟ of the derived class.
o Therefore, the public and protected members of the base class can
only be accessed by the member functions of derived class but,
cannot be accessed by the objects of the derived class.
Syntax:
class derived: private base
{
//Members of derived class;
};
Public:
o When a base class is publicly inherited by a derived class then „protected members‟ of base class becomes „protected members‟
and ‟public members‟ of the base class become „public members‟
of the derived class.
o Therefore the public members of the base class can be accessed
by both the member functions of derived class as well as the
objects of the derived class.
Syntax:
class derived: public base
{
//Members of derived class;
};
Protected:
o When a base class is protectedly inherited by a derived class,
„public and protected members‟ of the base class become
„protected members‟ of the derived class.
o Therefore the public and protected members of the base class can
be accessed by the member functions of derived class as well as
the member functions of immediate derived class of it but they
cannot be accessed by the objects of derived class
Syntax:
class derived: protected base
{
//Members of derived class;
};