当所有的构造器都会把一个相同的值赋值给某个指定的实例域时,我们可以进行显示初始化。
public class Dog { private String name = "goudan"; private int age; private char sex; public Dog(int age) { this.age = age; } public Dog(int age, char sex) { this.age = age; this.sex = sex; } }
当所有的构造器都会把一个相同的值赋值给某个指定的实例域时,我们可以进行显示初始化。
public class Dog { private String name = "goudan"; private int age; private char sex; public Dog(int age) { this.age = age; } public Dog(int age, char sex) { this.age = age; this.sex = sex; } }
转载于:https://www.cnblogs.com/zhju/p/8892138.html