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

What is Type casting in Java?

Some   times there  are  a  need to store a  value  of  one type  in to variable of  another  type.In such situations  we  must ...

Basic Concept’s of Object Oriented Programming

Basic   concept’s  of Object Oriented Programming : Object:- Objects  are basic  run time  entities  in an  object  orient...

Features of Java

Java is  simple  and  familiar   program  language:- learning and practicing java  is easy because it contains many features of c and c++. Java is  s...

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