当类声明了私有成员时,如果需要 获取(get) 或 设置(set) 这个私有成员的值,可以为这个私有成员编写get或set 方法
package cn.itcast.domain;
import java.util.Date;
public class User {
private String username;
private String password;
private String gender;
private Date birthday;
private String email;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
User u = new User();
u.setXXX();
u.getXXX();
你想给他赋值就用u.setXXX(); 取这个类的对象的某个值 就get