定义一个类,其中包含两个属性,并且提供对外访问的方法,提供一个默认的无参构造方法和两个参数的构造方法,以及输出方法。
如有帮助,请采纳。
public class Square extends Shape{
private int height;
private int width;
public void setHeight(int height) {
this.height = height;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public int getWidth() {
return width;
}
public Square(String colour) {
super(colour);
}
public Square(String colour, int height, int width) {
super(colour);
this.height = height;
this.width = width;
}
public void print(){
System.out.println("Square of height:"+height+",width:"+width);
}
}
完善Shape类,写一个Square子类,再测试运行。