Inheritance

Inheritance :

  • When one class inherits(has access to) the data members and member functions of another class, it is called inheritance.
  • It is the property of inheriting the characteristics and behavior of one class into another.
  • The class whose data members and member functions are inherited is called Base or Parent or Super class.
  • The class which inherits data members and member functions is called Derived or Child or Sub class.
  • Only private and protected members of a class can only be inherited.
  • A base class’s private members are never accessible directly from a derived class, but can be accessed through calls to the public and protected members of the base class.
Syntax to define a derived class :
class derived-class: access-specifier base-class

where access-specifier is one of public, protected, or private  and base-class is the name of a previously defined class which is to be inherited.

  • If the access-specifier is not used, then it is private by default.
  • When deriving a class from a public base class, public members of the base class become public members of the derived class and protected members of the base class become protected members of the derived class
  • When deriving from a protected base class,public and protected members of the base class become protected members of the derived class.
  • When deriving from a private base class,public and protected members of the base class become private members of the derived class.

Types :

Leave a Reply

Your email address will not be published. Required fields are marked *