Inheritance

Inheritance

Extending the Properties of one class to another class is known as inheritance.The main aim of the inheritance is reusability.In java language these inheritances are classified into following types.
  • Single or simple Inheritance
  • Multilevel Inheritance
  • Hierarchical Inheritance
  • Multiple Inheritance
  • Hybrid inheritance

Single or simple Inheritance

Extending the propertis of single parent class to single child class is known as Single or simple Inheritance.
syntax:
class parent
{
...
...
...
}
class child extends parent
{
...
...
...
}

Note:here "extends" Keyword is used to extends the parent class properties to child class.

Multilevel Inheritance

Extending the propertis of one class to another class in a sequential order is known as Multilevel Inheritance.
syntax:
class A
{
...
...
...
}
class B extends A
{
...
...
...
}
class C extends B
{
...
...
...
}
class D extends C
{
...
...
...
}

Note:if we create object for the 'D' class we can access A,B,C,D Classes.

Hierarchical Inheritance

Extending the propertis of Single class to multiple child classes known as Hierarchical Inheritance
syntax:
class A
{
...
...
...
}
class B extends A
{
...
...
...
}
class C extends A
{
...
...
...
}
class D extends A
{
...
...
...
}

Multiple Inheritance

Extending the propertis of Multiple parent classes to single child class known as Multiple Inheritance
syntax:
class A
{
...
...
...
}
class B
{
...
...
...
}
class C
{
...
...
...
}
class D extends A,B,C
{
...
...
...
}

Note: In Java Language multiple inheritance con't be supported at class level .To overcome this problem Interfaces are introduced.

Hybrid inheritance

Combination of above all Inheritances is known as Hybrid inheritance
syntax:
class A
{
...
...
...
}
class B extends A
{
...
...
...
}
class C extends D
{
...
...
...
}
class D extends B
{
...
...
...
}