重载
class MyRectangle{ int x, y; public MyRectangle() { x = 10; y = 20; } public MyRectangle(int a) { x = a; y = a; } public MyRectangle(int a, int b) { x = a; y = b; } }
Constructor chaining
public MyRectangle() { this(10,20); } public MyRectangle(int a) { this(a,a); } public MyRectangle(int a, int b) { x = a; y = b; }
Java 语法 索引 ----- 构造函数(constructor)
时间: 2024-12-25 15:24:08