Java实现:
观察以下代码,在注释部分添加代码。
要求实例化一个Square对象,通过设置height=3和width=5值,利用getArea()输出面积的值
注:使用System.out.println()方法输出。
public class Test {
public static void main(String[] args) {
//write code here
Square s = new Square();
s.setHeight(3);
s.setWidth(5);
System.out.print(s.getArea());
}
}
class Square{
private int height;
private int width;
public void setHeight(int height){
this.height=height;
}
public void setWidth(int width){
this.width=width;
}
public int getArea(){
return height*width;
}
}