/**
*/
public class User {
int id;
String name;
String pwd;
public User(int id){
this.id = id;
//用this.標明對象的” id ” 和形參的” id “區(qū)分
}
public User(){}
//通過形參列表的不同來構成構造方法的重載
public User(int id,String name){
this.id = id;
this.name = name;
}
/*不能再定義User(int id,String pwd) 形參的名字不指代類的屬性
pwd和name類型相同名字不同,在構造方法執(zhí)行時無法區(qū)分輸入的String型是name屬性還是pwd屬性
*/
public User(int id, String name, String pwd) {
this.id = id;
this.name = name;
this.pwd = pwd;
}
public static void main(String[] args) {
User u1 = new User();
User u2 = new User(001);
User u3 = new User(002,”n1″);
User u4 = new User(003,”n2″,”111111″);
}
}