从抽象类访问

时间:2012-04-15 18:12:05

标签: java

public abstract class Password  {
private String password;
private final static String ENCRYPTION_METHOD;

static  {
ENCRYPTION_METHOD = "CLEAR TEXT";
    }

public Password(String password)    {
    password = password;

}

public String getPassword() {
    return password;
}

public boolean matches (String aString) {
    if (aString.equals(password))   {
        return true;    }

        else    {
            return false;   }
        }

public String toString()    {
    return password;
}

public static String getEncryptionMethod()  {
    return ENCRYPTION_METHOD;
}

abstract String decrypt();

}

  public class EncryptedPassword extends Password   {
private final static String ENCRYPTION_METHOD;

static  {
ENCRYPTION_METHOD = "PERMUTATION";
    }

public EncryptedPassword(String password)   {
    super(password);
}


public boolean matches (String aString) {
    if  (aString.equals("True"))    {
            return true;    }

            else    {
            return false;   }
                }

public String toString()    {
    return "Password: " + super.toString();
}


public String decrypt() {

    return password;
}

public static String getEncryptionMethod()  {
    return ENCRYPTION_METHOD;
}

}

嗨,我想知道你们是否知道我在EncryptedPassword课上如何返回我的密码,但仍然保持具体并保持我的密码类摘要。有没有任何基本的方法。此外,抱歉可怕的格式..

1 个答案:

答案 0 :(得分:2)

您可以将方法更改为:

public String decrypt() {
    return getPassword();
}

或者,您可以将password字段的访问修饰符从private更改为protected