初認識java 之輸出個人資訊(內含過載方法)
阿新 • • 發佈:2018-11-29
public class Peopleinformation{ private String name; private String sex; private int age; private String post; private String tel; private String adress; public Peopleinformation(String name,String sex,int age){ this.name = name; this.sex = sex; this.age = age; } public Peopleinformation(String name,String sex,int age,String post){ this(name,sex,age); this.post = post; } public Peopleinformation(String name,String sex,int age,String post,String tel){ this(name,sex,age,post); this.tel = tel; } public Peopleinformation(String name,String sex,int age,String post,String tel,String adress){ this(name,sex,age,post,tel); this.adress = adress; } public String PeopleinformationInfo(){ return("這個人的資訊是"+name+" "+sex+" "+age+" "+post+" "+tel+" "+adress); } String getname(){ return name; } String getsex(){ return sex; } int getage(){ return age; } String getpost(){ return post; } String gettel(){ return tel; } String getadress(){ return adress; } public static void main(String[] args){ Peopleinformation p1 = new Peopleinformation("Mary","female",26,"HR Dirdctor","18081318888","DaTun road no. 6,chaoyang,Beijing"); System.out.println(p1.PeopleinformationInfo()); } }