package chapter03;
public class oop1 { public static void main(String[] args){ System.out.println(City.BEIJING.name); System.out.println(City.SHANGHAI.code); System.out.println(MyCity.SHANGHAI.name); System.out.println(MyCity.BEIJING.code); } }
enum City { BEIJING("北京", 1001), SHANGHAI("上海", 1002);
City( String name, int code ) { this.code = code; this.name = name; } public String name; public int code; }
class MyCity { public String name; public int code;
private MyCity(String name, int code) { this.code = code; this.name = name; }
public static final MyCity BEIJING = new MyCity("北京", 1001); public static final MyCity SHANGHAI = new MyCity("上海", 1002); }
|