创建一个使用访问控制的ZipCode类,以确保其zipCode实例变量始终具有五位数字的值。
/* from N o w J a v a . c o m */ public class Main{ public static void main(String[] arguments) { ZipCode zip1 = new ZipCode("444344"); ZipCode zip2 = new ZipCode("111110"); if (zip1.getZipCode() != "") { System.out.println("Zip1: " + zip1.getZipCode()); } if (zip2.getZipCode() != "") { System.out.println("Zip2: " + zip2.getZipCode()); } } } class ZipCode { private String zipCode = "";/** from 时 代 Java - nowjava.com**/ public ZipCode(String inZipCode) { setZipCode(inZipCode); } public void setZipCode(String inZipCode) { if (