calculate the area of rectangle a square a triangle by using constructor overloading
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;
}
}
Comments
Leave a comment