SOURCE CODE:
Interface.java
interface Area
{
final static float PI=(float) 3.14;
float compute(float x,float y);
}
class Rectangle implements Area
{
public float compute(float x,float y)
{
return x*y;
}
}
class circle implements Area
{
public float compute(float x,float y)
{
return (PI*x*x);
}
}
public class Interface
{
public static void main(String[] J)
{
Rectangle rec=new Rectangle();
circle cir=new circle();
Area area;
area=rec;
System.out.println("Area of the Rectangle = "+area.compute(10,20));
area=cir;
System.out.println("Area of the Circle = "+area.compute(10,0));
}
}
OUTPUT :
Area of the Rectangle = 200.0
Area of the Circle = 314.0
EmoticonEmoticon