Java Class (2)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.