Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AreaMain{
- public static void main(String Args[])
- {
- Area ar1 = new Area();
- Area ar2 = new Area(4,2);
- Area ar3 = new Area(9,7);
- System.out.print("\na = "+ar1.a+" b = "+ar1.b+"Rect area = " + ar1.Rect());
- System.out.print("\na = "+ar2.a+" b = "+ar2.b+"Parallelogram area = " + ar2.Parall());
- System.out.println("\na = "+ar3.a+" b = "+ar3.b+"Triangle area = " + ar3.Tri());
- }
- }
- class Area {
- int a;
- int b;
- Area()
- {
- System.out.print("\tDefault Const called!\n");
- a = 2;
- b = 3;
- }
- Area(int a, int b)
- {
- System.out.print("\tParameterized Const called!\n");
- this.a=a;
- this.b=b;
- }
- int Rect()
- {
- return a*b;
- }
- int Parall()
- {
- return a*b;
- }
- double Tri()
- {
- return 0.5*(double)(a*b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement