Topic : Type Of Inheritance: Single Multiple Multilevel Hierarchical hybrid

Type of Inheritance:

Based on Number of ways Inheriting the features of base class into derived class, it have Five Types, they are:




Single Inheritance:

In Single Inheritance, there exists single base class and single derived class. We already discussed the example of single inheritance in Our Inheritance tutorial: This type of inheritance enables a derived class to inherit properties and behavior from a single parent class or base class. thus enabling code reuse-ability as well as adding new features to the existing code. This makes the code much more elegant and less repetitive.


image: single Inheritance: infobrother

The Basic Syntax for Single Inheritance is:


     Access-Specifier    class     Base_Class 
{
    // Base Class Body:
}


class Derived_Class   : Base_class
{
    // Derived Class Body:
}


  • In Above Syntax:

    » Access-Specifier Defines the Scope and Visibility of a Class.
    » Class is The Keyword to Define Class.
    » Base_Class is the name of Class whose members will be inherited by Derived Class.
    » Derived_Class is the the name of Class Which will Inherit the Members of Base_Class
    » : colon " : " is the Special Character to make a Relationship between the Base and Derived Class.



Multiple Inheritance:

Multiple Inheritance represent a kind of inheritance when a derived class inherits properties of Multiple classes. For Example, there are three classes A, B, and C and derived Class is D as shown below.

NOTE: This Type of Inheritance is not Supported by .NET Languages like C#, F# etc.


image: Multiple Inheritance: infobrother

The Basic Syntax for Multiple Inheritance is:


     Access-Specifier    class     A 
{
    // Base Class Body:
}


Access-Specifier   class   B
{
    // Base Class Body:
}


class C   : A , B
{
    // Derived Class Body:
}


  • In Above Syntax:

    » Access-Specifier Defines the Scope and Visibility of a Class.
    » Class is The Keyword to Define Class.
    » Base_Class is the name of Class whose members will be inherited by Derived Class.
    » Derived_Class is the the name of Class Which will Inherit the Members of Base_Class
    » : colon " : " is the Special Character to make a Relationship between the Base and Derived Class.
    » The Derived Class "C" Inherit the Properties and Method of two Classes A, and B.
    » The Class C inherit the Members of Class A and B using Comma Operator.



Multi-Level Inheritance:

Multiple Inheritance represents a type of inheritance when a Derived class is a base class for another class. In Other words, deriving a class from a derived class is known as multi-level Inheritance. Simple multi-level Inheritance is shown in below image where Class Grandfather is a parent of Class Father and Class Father is a parent of Class Child.


image: Multilevel Inheritance: infobrother

In Above Picture, Father Inherited the Properties of Grandfather, and Child Inherited the Properties of Father. The Basic Syntax for Multi-Level Inheritance is:


     Access-Specifier    class     A 
{
    // Base Class Body:
}


class B   : A
{
    // Derived Class Body:
}


class C   : B
{
    // Derived Class Body:
}


  • In Above Syntax:

    » Access-Specifier Defines the Scope and Visibility of a Class.
    » Class is The Keyword to Define Class.
    » Base_Class is the name of Class whose members will be inherited by Derived Class.
    » Derived_Class is the the name of Class Which will Inherit the Members of Base_Class
    » : colon " : " is the Special Character to make a Relationship between the Base and Derived Class.
    » The Derived Class "C" Inherit the Properties and Method of two Classes A, and B.
    » Class A is the Base Class for Class B and Class C. B is the Derived Class of Class A and Base Class of Class C. and Class C is the Derived Class of Class B.



Hierarchical Inheritance:

When there is a Need to create Multiple Derived Classes That Inherit Properties of the same Base Class is known as Hierarchical Inheritance. For Example: Civil, Computer, Mechanical, Electrical are derived from Engineer. Natural language, Programming Language are derived from language.


image: Hierarchical Inheritance: infobrother

The Basic Syntax for such type of Inheritance is:


      Access-Specifier    class     Base_Class 
{
    // Base Class Body:


class A   : Base_class
{
    // Derived Class Body:
}


class B   : Base_class
{
    // Derived Class Body:
}


class C   : Base_class
{
    // Derived Class Body:
}


  • In Above Syntax:

    » Access-Specifier Defines the Scope and Visibility of a Class.
    » Class is The Keyword to Define Class.
    » Base_Class is the name of Class whose members will be inherited by Derived Class.
    » Derived_Class is the the name of Class Which will Inherit the Members of Base_Class
    » : colon " : " is the Special Character to make a Relationship between the Base and Derived Class.
    » The Derived Class "C" Inherit the Properties and Method of two Classes A, and B.
    » Class A, B and C is the Derived Classes of Class Base_class.



Hybrid Inheritance:

Combination of Multi-level and Hierarchical Inheritance will give us Hybrid Inheritance. this type of inheritance is also known as Virtual Inheritance.



image: Hybrid Inheritance: infobrother















I Tried my Best to Provide you complete Information regarding this topic in very easy and conceptual way. but still if you have any Problem to understand this topic, or do you have any Questions, Feel Free to Ask Question. i'll do my best to Provide you what you need.

Sardar Omar.
InfoBrother





WRITE FOR INFOBROTHER

Advertising






Advertisement