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

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.