class ProtectClass{ //user define exception public static final class NoAccessException extends Exception{ public String toString(){ return "No privilege to access this property(field/method)"; } } //static final defination section public static final int BANKACCOUNT_POS=0; public static final int BANKAPASSWORD_POS=1; //Inner property state array //只需要修改以下的对象元素访问全县数组即可动态控制用户可读/写的数据成员范围。(0,0 / 0,1 / 1,0 / 1,1) private static final int[] PROPERTY_ARRAY={0,1}; //get the property state array count private final int getPropertyCount(){ return (PROPERTY_ARRAY!=null)?PROPERTY_ARRAY.length:0; } //get the property available state public final boolean getPropertyAvailable(int pos){ return (pos>=0 && pos<getPropertyCount())?(PROPERTY_ARRAY[pos]==1):false; } //private property defination section private String bankAccount; private String bankPassword; private void setBankAccount(String bankAccount) throws NoAccessException{ if (getPropertyAvailable(BANKACCOUNT_POS)) this.bankAccount = bankAccount; else throw new NoAccessException(); } private void setbankPassword(String bankPassword) throws NoAccessException{ if(getPropertyAvailable(BANKAPASSWORD_POS)) this.bankPassword=bankPassword; else throw new NoAccessException(); }