public class Shapes {
private int length;
private int width;
/**
* This a constructor for an object
* by which parameter are passed in at
* object's creation
* @param side1
*/
public Shapes(int side1) {
setLength(side1);
setWidth(side1);
}
/**
* This is the other constructor notice it is overloaded
* which means the compiler knows which one to utilize
* at runtime based on the number of input parameters
* @param side1
* @param side2
*/
public Shapes(int side1, int side2){
setLength(side1);
setWidth(side2);
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public static void main(String[] args) {
Shapes square = new Shapes(3);
Shapes rectangle = new Shapes(8,2);
System.out.println("The square object has a length of " + square.getLength() +
"cm and a width of " + square.getWidth() + "cm\n");
System.out.println("The rectangle object has a length of " + rectangle.getLength() +
"cm and a width of " + rectangle.getWidth() + "cm");
}
}