Java类和对象的基本使用方式

 1 package Address;
 2 import java.util.Scanner;
 3 
 4 public class Address{
 5 Scanner sc=new Scanner(System.in);
 6 private String country; //国家
 7 private String province; //省份
 8 private int streetID; //街道编号
 9 private int postID; //邮编
10 private String city; //城市
11 Address()
12 {
13 System.out.println("请输入国家:");
14 country=sc.next();
15 System.out.println("请输入省份:");
16 province=sc.next();
17 System.out.println("请输入城市:");
18 city=sc.next();
19 System.out.println("请输入邮政编码:");
20 postID=sc.nextInt();
21 System.out.println("请输入街道编码:");
22 streetID=sc.nextInt();
23 }
24 public String getCountry() {
25 return country;
26 }
27 public int getStreetID()
28 {
29 return streetID;
30 }
31 public int getPostID() {
32 return postID;
33 }
34 public String getCity() {
35 return city;
36 }
37 public String getProvince() {
38 return province;
39 }
40 public static void main(String args[])
41 {
42 Address a=new Address();
43 System.out.println(" 国家:"+a.getCountry()+'\n'+" 省份:"+a.getProvince()+'\n'+" 城市:"+a.getCity()+'\n'
44 +" 街道编号:"+a.getStreetID()+'\n'
45 +" 邮政编码:"+a.getPostID());
46 }
47 }

 

 

posted @ 2020-07-10 20:06  靠谱杨  阅读(147)  评论(0编辑  收藏  举报