1 classProvince {2 Private intpid;3 PrivateString name;4 PrivateCity Citys [];5 Public voidSetcitys (city citys[]) {6 This. citys=Citys;7 }8 PublicCity [] getcity () {9 return This. Citys;Ten } One PublicProvince (intpid,string name) { A This. pid=pid; - This. name=name; - } the PublicString GetInfo () { - return"Province ID:" +pid+ ", Name:" +name; - } - } + classcity{ - Private intCID; + PrivateString cname; A PrivateProvince Province; at Public voidSetprovince (province province) { - This. province=Province; - } - PublicProvince Getprovince () { - return This. Province; - } in PublicCity (intcid,string CNAME) { - This. cid=CID; to This. cname=cname; + } - PublicString GetInfo () { the return"City ID:" +cid+ ", City Name:" +cname; * } $ }Panax Notoginseng - Public classDare the{ Public Static voidMain (String args[]) { +City AA =NewCity (1, "Jiangxi"); ACity BB =NewCity (2, "Hunan"); theProvince PR =NewProvince (0, "China"); + aa.setprovince (PR); - bb.setprovince (PR); $Pr.setcitys (Newcity[] {aa,bb}); $System.out.println ("***************** begins to take out provincial information ****************"); - System.out.println (Aa.getprovince (). GetInfo ()); -System.out.println ("***************** begins to take out city information ****************"); the System.out.println (Pr.getinfo ()); - for(intx = 0;x<pr.getcity (). length; x + + )Wuyi{System.out.println ("\t|-" +pr.getcity () [X].getinfo ()); the } -System.out.println ("***************** has all taken out ****************"); Wu } -}
View Co
1 classProvince {2 Private intpid;3 PrivateString name;4 PrivateCity Citys [];5 Public voidSetcitys (city citys[]) {6 This. citys=Citys;7 }8 PublicCity [] getcity () {9 return This. Citys;Ten } One PublicProvince (intpid,string name) { A This. pid=pid; - This. name=name; - } the PublicString GetInfo () { - return"Province ID:" +pid+ ", Name:" +name; - } - } + classcity{ - Private intCID; + PrivateString cname; A PrivateProvince Province; at Public voidSetprovince (province province) { - This. province=Province; - } - PublicProvince Getprovince () { - return This. Province; - } in PublicCity (intcid,string CNAME) { - This. cid=CID; to This. cname=cname; + } - PublicString GetInfo () { the return"City ID:" +cid+ ", City Name:" +cname; * } $ }Panax Notoginseng - Public classDare the{ Public Static voidMain (String args[]) { +City AA =NewCity (1, "Jiangxi"); ACity BB =NewCity (2, "Hunan"); theProvince PR =NewProvince (0, "China"); + aa.setprovince (PR); - bb.setprovince (PR); $Pr.setcitys (Newcity[] {aa,bb}); $System.out.println ("***************** begins to take out provincial information ****************"); - System.out.println (Aa.getprovince (). GetInfo ()); -System.out.println ("***************** begins to take out city information ****************"); the System.out.println (Pr.getinfo ()); - for(intx = 0;x<pr.getcity (). length; x + + )Wuyi{System.out.println ("\t|-" +pr.getcity () [X].getinfo ()); the } -System.out.println ("***************** has all taken out ****************"); Wu } -}
de
Java Class (2)