Inheritance

  • Inheritance is the capability of one class to inherit properties from another class.
  • For deriving the property of class,we use the keyword extends.
  • The Class which inherit the property from other class is called Sub Class or Derived Class or Child Class and the class from which the property is being inherited is called Super Class or Parent Class.

Syntax-

class subclassname extends superclassname
{
//statement
---------
}

Need For Inheritance

  • The Capability to express the inheritance relation which ensure the closeness with the real world.
  • The advantage of inheritance is Reusability,faster development time,easier maintenance and easy to extend.
  • Transitive nature in inheritance.

Visibility Modes

  • It is any of the access labels: private, public or protected
  • It defines the accessibility of the members of the base class within the derived class
  • If the visibility mode is not specified, it will be taken as private by default

Difference Between Private and Protected Members

  • Private members can never be inherited.
  • Only the public and protected members can be inherited to the derived class. 

Visibility Modes

Visibility Mode

Accessbility of members by various object

Making private member inheritable

  • Private members of the base class cannot be inherited with any of the visibility mode.
  • One is by making the visibility mode of private members as public, but they will be exposed to the outside world.
  • Another is to convert the private members into protected so that they will be hidden from the outside world but can be inherited.

Types of INHERITANCE

  • SINGLE INHERITANCE 

  •  MULTIPLE INHERITANCE 

  • HIERARCHICAL INHERITANCE 

  • MULTILEVEL INHERITANCE 

  • HYBRID INHERITANCE

SINGLE INHERITANCE

  • Derivation of a class from only one base class is called SINGLE Inheritance.

 

 

MULTIPLE INHERITANCE

  • Derivation of a class from SEVERAL (TWO OR MORE) base classes is called MULTIPLE Inheritance.

 

HIERARCHICAL INHERITANCE

  • Derivation of SEVERAL classes from SINGLE base class is called HIERARCHICAL Inheritance.

 

MULTILEVEL INHERITANCE

  • When a sub class is derived from a base class which itself is derived from another class, it is known as MULTILEVEL Inheritance

 

HYBRID INHERITANCE

  • Derivation of a class involving more than one form of Inheritance is known as HYBRID inheritance.