Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface Shape
- {
- final static double pi=3.14;
- abstract void ComputeArea(double x,double y);
- }
- class Rectangle implements Shape
- {
- public void ComputeArea(double x,double y)
- {
- double area;
- area=x*y;
- System.out.println("area= "+area);
- }
- }
- class Circle implements Shape {
- public void ComputeArea(double x, double y)
- {
- double area_circle;
- area_circle=pi*x*x;
- System.out.println("Circle area= "+area_circle);
- }
- }
- public class InterfaceDemo
- {
- public static void main(String[] args)
- {
- Shape ob;
- Rectangle rect=new Rectangle();
- ob=rect;
- ob.ComputeArea(10.0,20.0);
- Circle circ=new Circle();
- ob=circ;
- ob.ComputeArea(10.0,0.0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement