Monday, April 25, 2016

What is Inheritance?

Inheritance is a relationship between classes where one class is the parent/super class of another. Classes can inherit from another class only, it cannot inherit from multiple classes but can inherit from multiple Interfaces. This is accomplished by putting a colon after the class name when declaring the class and naming the class to inherit from—the base class—after the colon.

The different types of inheritance that are there are as follows:
  • Single Inheritance
    In this type one child class is created from one base class
  • Hierarchical Inheritance
    In this type more than one child class is created from a single base class
  • Multi-Level Inheritance
    In this type one child class is derived from a class which is derived from another base class
  • Hybrid Inheritance
    This type is a combination of Single, Multi-level and Hierarchical inheritance
  • Multiple Inheritance
    This type is not supported by C# where a class is derived from multiple base classes, but a class can be derived from one base class and multiple interfaces
There are two types of inheritance mechanism, which are as follows:
  • Implementation Inheritance
    When a class is inherited, inherits all the members of the base class
  • Interface Inheritance
    When the class only inherits the signature of the methods of the base class

No comments:

Post a Comment