package December.dome12063;
public class Rectangle {
int width;
int height;
public Rectangle() {
System.out.println("无参的构造方法");
}
public Rectangle(int width,int height) {
System.out.println("有参的构造方法");
this.height=height;
this.width=width;
}
public void setWidth(int width) {
this.width=width;
}
public int getWidth() {
return width;
}
public void setHeight(int height) {
this.height=height;
}
public int getHeight() {
return height;
}
public void show() {
int area=width*height;
int premeter=(width+height)*2;
System.out.println("周长"+premeter+"面积"+area);
}
}
package December.dome12063;
public class test {
public static void main(String[]args) {
Rectangle r1=new Rectangle(8,9);
r1.show();
Rectangle r2=new Rectangle();
r2.setHeight(8);
r2.setWidth(9);
r2.show();
}
}
package December.dome12063;public class Rectangle { int width; int height; public Rectangle() { System.out.println("无参的构造方法"); } public Rectangle(int width,int height) { System.out.println("有参的构造方法"); this.height=height; this.width=width;.