![]() |
![]() |
Java Interface | |
Java Class vs Interface | |
Java Multiple Inheritance | |
Java Nested Interface |
Java Packages | |
Java Built in packages | |
Java Package Access Specifiers |
Java Programs | |
Java Keywords Dictionary | |
Java Interview Questions |
In Multilevel Inheritance, There is a Base class which is accessed by derived class. Again that derived class is again accessed by next Derived class and so on.
In fig. Class A is the base class for Class B. Then again Class is acts as a base class for Class C. While creating an object we should always create an object of last derived class in the level.
Consider a relationship between grandparent and parent, All the grandparent properties are applied to the parent before grandparent passes away. Then again the all properties of parent are applied to the children. This is called as Multilevel Inheritance.
class className1 { // className1 members } class className2 extends className1 { // className2 members } class classNameN extends className2 { // classNameN members }
Example to show the use of multilevel inheritance using family structure
class Grand { void show1() { System.out.println("I'm Grandparent"); } } class Parent { void show2() { System.out.println("I'm Parent"); } } class Child { void show3() { System.out.println("I'm Child"); } } class Family { public static void main(String args[]) { Child childObj = new Child(); childObj.show1(); childObj.show2(); childObj.show3(); } }