Interface-inheritance

Write a program that illustrate the interface inheritance. Interface P is extended by P1 and P2 interfaces. Interface P12 extends both P1 and P2. Each interface declares one method and one constant. Create one class that implemetns P12. By using the object of the class invokes each of its method and displays constant.

interface P
{
	final int p = 1;
	void p_method();
}

interface P1 extends P
{
	final int p1 = 2;
	
	void p1_method();
}

interface P2 extends P
{
	final int p2 = 3;
	
	 void p2_method();
}

interface P12 extends P1, P2
{
	final int p12 = 4;
	
	 void p12_method();
}

class Class implements P12
{
	public void p_method()
	{
		System.out.println("Hello from P");
		System.out.println("P => " + p);
	}
	public void p1_method()
	{
		System.out.println("Hello from P1");
		System.out.println("P1 => " + p1);
	}
	public void p2_method()
	{
		System.out.println("Hello from P2");
		System.out.println("P2 => " + p2);
	}
	public void p12_method()
	{
		System.out.println("Hello from P12");
		System.out.println("P12 => " + p12);
	}
}

public class Practical17
{
	public static void main(String[] args)
	{
		P12 pr = new Class();
		pr.p_method();
		pr.p1_method();
		pr.p2_method();
		pr.p12_method();
	}
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here