Program to find area of rectangle and circle using Interface
interface Area //interface defined
{
float pi=3.14F;
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);
}
}
class InterfaceTest2
{
public static void main(String args[])
{
Rectangle rect=new Rectangle();
Circle cir=new Circle();
Area a;
a=rect;
System.out.println("Area of rectangle : "+a.compute(5,10));
a=cir;
System.out.println("Area of circle : "+a.compute(5,0));
}
}
/*
Area of rectangle : 50.0
Area of circle : 78.5
*/
interface Area //interface defined
{
float pi=3.14F;
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);
}
}
class InterfaceTest2
{
public static void main(String args[])
{
Rectangle rect=new Rectangle();
Circle cir=new Circle();
Area a;
a=rect;
System.out.println("Area of rectangle : "+a.compute(5,10));
a=cir;
System.out.println("Area of circle : "+a.compute(5,0));
}
}
/*
Area of rectangle : 50.0
Area of circle : 78.5
*/
This post offers clear idea in support of the new viewers of blogging, that truly how to
ReplyDeletedo blogging.
My webpage: laser cellulite treatment
what does float compute(float x, float y) do ?
ReplyDeletelebron 18
ReplyDeletestephen curry shoes
yeezy
off white
golden goose sneakers
stone island
bape
kd shoes
supreme new york
longchamp
Area area means
ReplyDeleteArea area meanz
ReplyDeletealexander mcqueen shoes
ReplyDeleteggdb outlet
off white nike
kyrie spongebob
kd shoes