How to use multilevel inheritance in java

In this article we learn multilevel inheritance by using notepad.
A class can be derived from a derived class which is known as multilevel inheritance.

0

Step 1: Lets open the notepad and write the following code:
//Code
class A
{
void disp()
{
System.out.println(“disp method”);
}
}
class Test extends A
{
void show()
{
System.out.println(“show method”);
}
}
class demo extends Test
{
public static void main(String arg[])
{
demo d=new demo();
d.show();
d.disp();
}
}

Step2: In this program we use “extends” for inherit the all properties from base class or parents class.

Step 3: Name it as “multy.java”and save the file in any location i saved at “c:/kiran/program”.

Step 4: Set the path (path set means where you save your java file).

1

Step 5: Now write the following code for checking my java file is compiling or not.
javac multy.java

2

 

My java program compiled successfully.

Step 6: write the following code in command prompt. press enter and see the output.
java demo
// demo is a class name which is written in my “multy.java” file.
Output

3

Happy coding.

Tags: , ,