-2
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 类中返回我的密码,但仍然保持它具体并保持我的密码类抽象。有没有什么基本的方法。另外,对于糟糕的格式感到抱歉..

4

1 回答 1

2

您可以将方法更改为:

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

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

于 2012-04-15T18:22:16.167 回答