Saturday, August 3, 2013

PROGRAM USING INTERFACE

Interface  Area 
{
 double pi=3.14; 
double compute(double x,double y);
 }
 class Rect implements Area
 {
 public double compute(double x,double y)
 { 
return x*y; 
}
 }
 class Tri implements Area 
{
 public double compute(double x,double y)
 {
 return x*y/2; 

}
 class Circle implements Area 
{
 public double compute(double x,double y) 
{
 return pi*x*x;
 }
 }
 class Area_Demo
 {
 public static void main(String arg[]) 
{
 Area A;
 Rect r=new Rect(); 
Tri t=new Tri();
 Circle c=new Circle();
 A=r; System.out.println("The Area of rectangle is:"+A.compute(10,20));
 A=t; System.out.println("The Area of Triangle  is :"+A.compute(10,12));
 A=c; System.out.println("The Area of Circle  is :"+A.compute(10,12)); 

No comments:

Post a Comment

Animated Social Gadget - Blogger And Wordpress Tips