Advertisement
brandblox

Java lab 1 (30/10/2023)

Oct 30th, 2023
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. interface Shape
  2. {
  3.     final static double pi=3.14;
  4.     abstract void ComputeArea(double x,double y);
  5. }
  6. class Rectangle implements Shape
  7. {
  8.     public void ComputeArea(double x,double y)
  9.     {
  10.         double area;
  11.         area=x*y;
  12.         System.out.println("area= "+area);
  13.     }
  14. }
  15. class Circle implements Shape {
  16.     public void ComputeArea(double x, double y)
  17.     {
  18.         double area_circle;
  19.         area_circle=pi*x*x;
  20.         System.out.println("Circle area= "+area_circle);
  21.     }
  22. }
  23.  
  24. public class InterfaceDemo
  25. {
  26.     public static void main(String[] args)
  27.     {
  28.         Shape ob;
  29.         Rectangle rect=new Rectangle();
  30.         ob=rect;
  31.         ob.ComputeArea(10.0,20.0);
  32.         Circle circ=new Circle();
  33.         ob=circ;
  34.         ob.ComputeArea(10.0,0.0);
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement