package java02;
//理解类的构造函数的定义,调用,重载。
class Rect {
double sideA, sideB;
Rect() {
}
Rect(double a, double b) {
sideA = a;
sideB = b;
}
double computerArea() {
return sideA * sideB;
}
double computerGirth() {
return (sideA + sideB) * 2;
}
}
public class 类的构造 {
public static void main(String args[]) {
Rect r1 = new Rect();// 默认初始为0
Rect r2 = new Rect(3, 4);
double area1 = r1.computerArea();
double area2 = r2.computerArea();
double area3 = r2.computerGirth();
System.out.println(area1);
System.out.println(area2);
System.out.println(area3);
}
}