黑马程序员技术交流社区
标题:
定义一个长方形类,定义求周长和面积的方法,然后定义一个测试类进行测试。
[打印本页]
作者:
小b,试试就试试
时间:
2016-7-29 21:40
标题:
定义一个长方形类,定义求周长和面积的方法,然后定义一个测试类进行测试。
class ChangXing {
public static void main(String[] args) {
Chang c1 = new Chang(10,20);
c1.getZhou();
c1.getMian();
}
}
class Chang{
private int length;
private int weith;
public Chang(){}
public Chang(int length,int weith){
this.length=length;
this.weith=weith;
}
public void setLength(int length){
this.length=length;
}
public int getLength(){
return length;
}
public void setWeith(int weith){
this.weith=weith;
}
public int getWeith(){
return weith;
}
public void getZhou(){
System.out.println(2*(length+weith));
}
public void getMian(){
System.out.println(length*weith);
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2