Question #303856

calculate the area of rectangle a square a triangle by using constructor overloading






Expert's answer

public class Main {
    private int width;
    private int height;

    public Main(int widthOrBase, int height) {
        width = widthOrBase;
        this.height = height;
    }

    public Main(int side) {
        width = side;
        height = side;
    }

    public int rectangleArea() {
        return width * height;
    }

    public int squareArea() {
        return width * height;
    }

    public double triangleArea() {
        return 0.5 * width * height;
    }
}
LATEST TUTORIALS
APPROVED BY CLIENTS