现在的位置: 首页 > 综合 > 正文

java 习题 返回类的信息

2018年09月14日 ⁄ 综合 ⁄ 共 840字 ⁄ 字号 评论关闭
View Code

 1 class Address{
2 private String Country;
3 private String Province;
4 private String City;
5 private String Street;
6 private int Postcode;
7 public Address(String Co,String P,String C,String S,int Po){
8 this.Country=Co;
9 this.Province=P;
10 this.City=C;
11 this.Street=S;
12 this.Postcode=Po;
13 }
14 public String getContry(){
15 return this.Country;
16 }
17 public String getProvince(){
18 return this.Province;
19 }
20 public String getCity(){
21 return this.City;
22 }
23 public String getStreet(){
24 return this.Street;
25 }
26 public int getPostcode(){
27 return this.Postcode;
28 }
29
30
31 }
32 public class Seqlist {
33 public static void main(String args[]){
34 Address Ars=new Address("China","Hunan","Zhuzhou","WenhuaRoad",412008);
35 System.out.print(Ars.getContry()+"\t"+Ars.getProvince()+"\t"+Ars.getCity()+"\t"+Ars.getStreet()+"\t"+Ars.getPostcode()+"\n");
36
37 }
38
39 }

编写测试一个代表地址的类Address,地址信息包括国家,省份,城市,街道,邮编组成。并返回完整的信息。

抱歉!评论已关闭.