Java实例域初始化方式
1.构造器
public class Employee {
private String name;
private String gender;
private int age;
private double salary;
public Employee() {
this.salary = 1000.0;
}
public Employee(String name, String gender, int age, double salary) {
this.name = name;
this.gender = gender;
this.age = age;
this.salary = salary;
}
}
2.域声明
public class Employee {
private String name;
private String gender;
private int age;
private double salary = 1000.0;
public Employee() {
}
public Employee(String name, String gender, int age, double salary) {
this.name = name;
this.gender = gender;
this.age = age;
this.salary = salary;<