Program to find area of rectangle and circle using Interface

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
*/

6 comments:

Anonymous said...

This post offers clear idea in support of the new viewers of blogging, that truly how to
do blogging.

My webpage: laser cellulite treatment

Anonymous said...

what does float compute(float x, float y) do ?

yanmaneee said...

lebron 18
stephen curry shoes
yeezy
off white
golden goose sneakers
stone island
bape
kd shoes
supreme new york
longchamp

Joseph said...

Area area means

Joseph said...

Area area meanz

Anonymous said...

alexander mcqueen shoes
ggdb outlet
off white nike
kyrie spongebob
kd shoes

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|