Java通过重载设置默认值。
使用this调用更多参数的其构造方法。
public class Cat {
String name;
int age;
int color;
//默认值
public Cat(){
this("Tom", 0, 1);
}
public Cat(String name, int age, int color){
this.name = name;
this.age = age;
this.color = color;
}
}