声明一个矩形类Reosrn,其中有多少构造方法。用不同的构造方法创建对象,并输出矩形的周长和面积 10
1个回答
展开全部
public class Reosrn {
private int x = 0;
private int y = 0;
public Reosrn() {
}
public Reosrn(int x) {
this.y = x;
}
public Reosrn(int x, int y) {
this.x = x;
this.y = y;
}
//周长
public int getZC() {
return 2 * (x + y);
}
//面积
public int getMJ() {
return x * y;
}
public static void main(String[] args) {
Reosrn r1 = new Reosrn();
System.out.println("r1周长" + r1.getZC());
System.out.println("r1面积" + r1.getMJ());
Reosrn r2 = new Reosrn(5);
System.out.println("r2周长" + r2.getZC());
System.out.println("r2面积" + r2.getMJ());
Reosrn r3 = new Reosrn(5, 4);
System.out.println("r3周长" + r3.getZC());
System.out.println("r3面积" + r3.getMJ());
}
}
private int x = 0;
private int y = 0;
public Reosrn() {
}
public Reosrn(int x) {
this.y = x;
}
public Reosrn(int x, int y) {
this.x = x;
this.y = y;
}
//周长
public int getZC() {
return 2 * (x + y);
}
//面积
public int getMJ() {
return x * y;
}
public static void main(String[] args) {
Reosrn r1 = new Reosrn();
System.out.println("r1周长" + r1.getZC());
System.out.println("r1面积" + r1.getMJ());
Reosrn r2 = new Reosrn(5);
System.out.println("r2周长" + r2.getZC());
System.out.println("r2面积" + r2.getMJ());
Reosrn r3 = new Reosrn(5, 4);
System.out.println("r3周长" + r3.getZC());
System.out.println("r3面积" + r3.getMJ());
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询