首页 > 代码库 > Java 语法 索引 ----- 构造函数(constructor)

Java 语法 索引 ----- 构造函数(constructor)

重载

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; }