Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- abstract class shape
- {
- int dim1,dim2;
- void read()
- {
- Scanner t = new Scanner (System.in);
- System.out.println("enter dim1 and dim2");
- dim1 = t.nextInt();
- dim2 = t.nextInt();
- int z = dim1*dim2;
- System.out.println("default area is "+z);
- }
- abstract void area();
- }
- class circle extends shape
- {
- double area1;
- void area()
- {
- Scanner t = new Scanner (System.in);
- System.out.println("enter radius of circle");
- int r = t.nextInt();
- area1 = 3.142*r*r;
- System.out.println("Area of circle is"+area1);
- }
- }
- class rectangle extends shape
- {
- int area2;
- void area()
- {
- Scanner t = new Scanner(System.in);
- System.out.println("enter lenght and breadth");
- int l = t.nextInt();
- int b = t.nextInt();
- area2 = l*b;
- System.out.println("Area of rectangle is"+area2);
- }
- }
- class triangle extends shape
- {
- int area3;
- void area()
- {
- Scanner t = new Scanner(System.in);
- System.out.println("enter height and base");
- int h = t.nextInt();
- int b = t.nextInt();
- area3 = h*b/2;
- System.out.println("Area of triangle is"+area3);
- }
- }
- class test
- {
- public static void main(String args[])
- {
- circle c = new circle ();
- c.read();
- c.area();
- rectangle r = new rectangle();
- r.area();
- triangle t = new triangle();
- t.area();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement