Tuesday, 29 August 2017

how to illustrates interface inheritance in java program

Java program that illustrates interface inheritance.

Create two interface p1and p2 then interface p which extends p1 and p2 and then interface p12 which extends p12.

Each interface declare one constants and one method.

Create class Q which implements p12 and define all the methods of interface which displays value of constants.


interface p
          static public final int P = 10;
          void DisplayP();
interface p1 extends p{
          static public final int P1 = 20;
          void DisplayP1();
interface p2 extends p{
          static public final int P2 = 30;
          void DisplayP2();
interface p12 extends p1, p2{
          static public final int P12 = 40;
          void DisplayP12();
class Q implements p12 {
          public void DisplayP()
                   System.out.println("interface p:" + P);
          public void DisplayP1()
                   System.out.println("interface p1:" + P1);
          public void DisplayP2(){
                   System.out.println("interface p2" + P2);
          public void DisplayP12()
                   System.out.println("interface p2:" + P12);
          public static void main(String args[])
                   Q q = new Q();



interface inheritance core java


Post a Comment