OOP Concepts: Basic Understanding of Inheritance

Md. Nazmul Hasan
1 min readJul 10, 2021

Inheritance is also know as IS-A relationship. The main advantage of inheritance is code reuse-ability. We can implement inheritance using extends keyword. Lets understand with examples …

In the below code section illustrates four scenarios about how inheritance behave.

Multilevel Inheritance

Java doesn’t support multiple inheritance but provides support of multilevel inheritance. Lets see the code example.

Methods available to class A are automatically available to class C. And Methods available to A & B are available to class C.

Hierarchical inheritance

One class can act as parent for multiple child classes called Hierarchical inheritance. Lets see the code example.

Why java doesn’t provide support for multiple inheritance?

Java doesn’t provide support for multiple inheritance because of ambiguity problem. Lets see the code example.

Note: Every java class extends Object class directly if it doesn’t extends any other class. So no multiple inheritance in java.
Java also doesn’t provide support for cyclic inheritance because it’s really not required.

Some additional behavior analysis of java inheritance.

--

--