Java Program using multilevel inheritance


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


class A { 
    //statement
}

class B extends A { 
   //statement
}

class C extends B { 
    //statement
}

Example: How to implement multilevel inheritance in java.

import java.util.Scanner;

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

class B extends A {

    void input() {
        System.out.print("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:30
The value of a is:30