/**
*/
public class User {
int id;
String name;
String pwd;
public User(int id){
this.id = id;
//用this.標(biāo)明對(duì)象的” id ” 和形參的” id “區(qū)分
}
public User(){}
//通過(guò)形參列表的不同來(lái)構(gòu)成構(gòu)造方法的重載
public User(int id,String name){
this.id = id;
this.name = name;
}
/*不能再定義User(int id,String pwd) 形參的名字不指代類(lèi)的屬性
pwd和name類(lèi)型相同名字不同,在構(gòu)造方法執(zhí)行時(shí)無(wú)法區(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″);
}
}