PROGRAM FOR CALCULATING AREA OF A RECTANGLE AND CIRCLE USING INTERFACES

import java.lang.*; interface Area {               final static float pi=3.14F;               float compute (float x,float y); }...

import java.lang.*;
interface Area
{
              final static 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 InterfaceTest
{
  public static void main(String args[])
   {
            Rectangle rect=new Rectangle();
            Circle cir=new Circle();
            Area area;
            area=rect;
            System.out.println("Area of Rectangle="  +area.compute(10,20));
            area=cir;
            System.out.println("Area of Circle="  +area.compute(10,20));
    }
}


OUTPUT:

Area of Rectangle=200.0

Area of Circle=314.0


Related

How Many Ways can you Create a Threads in Java?

Threads  are  implemented  in  the  form of  objects  that contain method  called  run(). The run() method is the heart and soul of any thread. It make u...

Write about SYNCHRONIZATION in Java?

SYNCHRONIZATION: Threads that use their own data and methods provided  inside their run( ) methods. What happens when they try to use data and methods outside themselves  on such occa...

Explain about Various Types of Operators in Java?

Java has rich set of operators. ® Operators are of any symbol that tells the computer to perform certain mathematical (Or) logical manipulations. ® Operat...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item