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
*/
6 comments:
This post offers clear idea in support of the new viewers of blogging, that truly how to
do blogging.
My webpage: laser cellulite treatment
what does float compute(float x, float y) do ?
lebron 18
stephen curry shoes
yeezy
off white
golden goose sneakers
stone island
bape
kd shoes
supreme new york
longchamp
Area area means
Area area meanz
alexander mcqueen shoes
ggdb outlet
off white nike
kyrie spongebob
kd shoes
Post a Comment