Class

public class Circle{
    double radius;
    Circle(){

    }
    Circle(double r){
        radius=r;
    }
    void area(){
        System.out.println(Math.PI*Math.pow(radius, 2));
    }
}
public class Rectangle {
    double width, height;
    Rectangle(){
        width=-1;
        height=-1;
    }
    Rectangle(double width, double height){
        this.width = width;
        this.height = height;
    }
    Rectangle(double x){
        width=x;
        height=x;
    }
    void area(){
        System.out.println(width*height);
    }

}
public class Triangle extends Rectangle{
    Triangle(double base, double height){
        super(base,height);
    }
    Triangle(){
        super();
    }
    Triangle(double x){
        super(x);
    }
    void area(){
        System.out.println(0.5*width*height);
    }
}

public class Main{
    public static void main(String args[]){
        Rectangle rec = new Rectangle(2.0,5.0);
        Triangle tri = new Triangle(2.0,5.0);
        Circle cir = new Circle(3.0);
        rec.area();
        tri.area();
        cir.area();
    }
}

No comments:

Post a Comment