What is multilevel inheritance in JAVA

What is multilevel inheritance in JAVA

Multi Level Inheritance in Java

Java is an object-oriented language. One of the core concepts in the language is – Inheritance i.e. a child object may acquire all the properties and behaviour of the parent object. It is an essential component of OOPS concepts and supports ‘Reusability’ in Java. Now, the question comes what is the multilevel inheritance in Java and how does it help you in programming? In this blog, we’ll try to cover this with an example along with few more questions a novice developer might have –

“What is multilevel inheritance?”

“What is the difference between multiple and multilevel inheritance?”

“Can you demonstrate multilevel inheritance in Java using a small program?”

Multilevel Inheritance in Java

Multilevel inheritance occurs when we have a structure where a class is extending a class, and that class is also extending another class. For example, look at the image below. The child class is extending a class called L1, and class L1 extends another class L2. This is known as multilevel inheritance. If you look carefully, you’ll realise that class child implicitly inherits all the properties and behaviours of class L2.

Let’s understand this with a real-life example.

Multilevel inheritance in Java – child class inherits all the properties of parent class L1 and grandparent class L2

Person.java

Teacher.java

TeachingAssociate.java

MultilevelInheritance.java

Output –

Person is – Chad   Course name is – Mathematics No. of Hours per week – 13

Hope this example helps you understand this aspect of inheritance in Java. Coming back to the questions noted at the start of the blog –

Does Java support multilevel inheritance?

Yes, Java does support this. Note that Java does NOT support multiple inheritance.

What is multilevel inheritance?

As demonstrated above, a class extends another parent class and the parent class extends a ’grand-parent’ class.

What is the difference between multiple and multilevel inheritance?

Can you demonstrate multilevel inheritance in Java using a small program?

Please feel free to ask your questions in the comments section and let us know if you feel the article has helped you in understanding this inheritance concept better.

Reference about simple inheritance in Java – https://www.w3schools.com/java/java_inheritance.asp

Also Read –

Please follow and like us:
Pin Share

Leave a Reply

Your email address will not be published. Required fields are marked *