Q:

Java program to implement the interface with multi-level inheritance

belongs to collection: Java Interface Programs

0

Java program to implement the interface with multi-level inheritance

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to implement the interface with multi-level inheritance is given below. The given program is compiled and executed successfully.

// Java program to implement the interface 
// with multi-level inheritance

interface Inf {
  void sayHello();
}

class Sample1 implements Inf {
  public void sayHello() {
    System.out.println("Hello World");
  }
}

class Sample2 extends Sample1 {
  public void sayHello1() {
    System.out.println("Hello World1");
  }
}

class Sample3 extends Sample2 {
  public void sayHello2() {
    System.out.println("Hello World2");
  }
}

public class Main {
  public static void main(String[] args) {
    Sample3 S = new Sample3();

    S.sayHello();
    S.sayHello1();
    S.sayHello2();
  }
}

Output:

Hello World
Hello World1
Hello World2

Explanation:

In the above program, we created an interface Inf. Then we implemented the Inf interface in the Sample1 class. Then we implemented Sample1 into Sample2 and Sample2 into Sample3.

The Main class contains a method main(). The main() method is the entry point for the program, here we created the object of the Sample3 class. After that, we called all abstracted methods and printed the result.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java program to implement multiple-inheritance usi... >>
<< Java program to implement multiple interfaces in t...