Java Program using multilevel inheritance


In this program, You will learn how to implement multilevel inheritance in Java.


class A { }

class B extends A { }

class C extends B { }


Example: How to implement multilevel inheritance in Java

Run it Now
import java.util.Scanner;

class A {
    int a;
    Scanner sc = new Scanner(System.in);
}

class B extends A {

    void input() {
        System.out.println("Enter a Number :");
        a = sc.nextInt();
    }
}

class Main extends B {

    void display() {
        System.out.println("The value of a is :" + a);
    }

    public static void main(String args[]) {
        Main obj = new Main();
        obj.input();
        obj.display();
    }
}

Output:

Enter a Number :10
The value of a is :10