Manu

Saturday, November 19, 2016

Write a program that illustrates interface inheritance. Interface P is extended by P1and P2. Interface P12 inherits from both P1 and P2.Each interface declares one constant and one method. class Q implements P12.Instantiate Q and invoke each of its methods. Each method displays one of the constants

CODE :
interface P
{
    public static final int p=5;
    void methodP();
}
interface P1 extends P
{
    public static final int p1=10;
    void methodP1();
}
interface P2 extends P
{
    public static final int p2=15;
    void methodP2();
}
interface P12 extends P1,P2
{
    public static final int p12=20;
    void methodP12();
}
class Q implements P12
{
    public void methodP12()
    {
        System.out.println("P12 Class Method Constant : "+p12);
    }
    public void methodP1()
    {
        System.out.println("P1 Class Method Constant : "+p1);
    }
    public void methodP2()
    {
        System.out.println("P2 Class Method Constant : "+p2);
    }
    public void methodP()
    {
        System.out.println("P Class Method Constant : "+p);
    }
}
class MainClass
{
    public static void main(String args[])
    {
        Q obj=new Q();
        obj.methodP12();
        obj.methodP1();
        obj.methodP2();
        obj.methodP();
    }
}

OUTPUT :

No comments:

Post a Comment