Introduction
Please go through my first article on Single Level Inheritance in Java:
In this article, we learn about multilevel inheritance using Notepad. A class can be derived from a derived class and that is known as multilevel inheritance.
Step 1
Let's open 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();
- d.show();
- d.disp();
- }
- }
Step 2
In this program we use "extends" to inherit all the properties from the base class or the parent's class.
Step 3
Name it "multy.java" and save the file in any location. I saved mine at "c:/kiran/program".
Step 4
Open a command prompt (press Windows + R and write cmd and hit OK).
Step 5
Go to "c:/app" using the command prompt.
Step 6
Set the path (path set means where you save your Java file).
Step 7
Now write the following code for checking whether or not the Java file has compiled.
My Java program compiled successfully.
Step 8
Write the following code in the command prompt. Press Enter and see the output.
Output
Happy coding.