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.


Step 1: Lets open the notepad and write the following 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();;

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

Step 3: Name it as “”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).


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



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 “” file.


Happy coding.

Tags: , ,