Advertisement
AnindyaBiswas

AreaMain

May 5th, 2022
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AreaMain{
  4.     public static void main(String Args[])
  5.     {
  6.         Area ar1 = new Area();
  7.         Area ar2 = new Area(4,2);
  8.         Area ar3 = new Area(9,7);
  9.         System.out.print("\na = "+ar1.a+" b = "+ar1.b+"Rect area = " + ar1.Rect());
  10.         System.out.print("\na = "+ar2.a+" b = "+ar2.b+"Parallelogram area = " + ar2.Parall());
  11.         System.out.println("\na = "+ar3.a+" b = "+ar3.b+"Triangle area = " + ar3.Tri());
  12.     }
  13. }
  14.  
  15. class Area {
  16.     int a;
  17.     int b;
  18.    
  19.     Area()
  20.     {
  21.         System.out.print("\tDefault Const called!\n");
  22.         a = 2;
  23.         b = 3;
  24.     }
  25.     Area(int a, int b)
  26.     {
  27.         System.out.print("\tParameterized Const called!\n");
  28.         this.a=a;
  29.         this.b=b;
  30.     }
  31.    
  32.     int Rect()
  33.     {
  34.         return a*b;
  35.     }
  36.    
  37.     int Parall()
  38.     {
  39.         return a*b;
  40.     }
  41.    
  42.     double Tri()
  43.     {
  44.         return 0.5*(double)(a*b);
  45.     }
  46.    
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement