...
Wiki Markup |
---|
Technically, a private method cannot be hidden or overridden. There is no requirement that private methods with the same signature in the subclass and the superclass, bear any relationship in terms of having the same return type or {{throws}} clause, the necessary conditions for hiding \[[JLS 2005|AA. Bibliography#JLS 05]\]. Consequently, hiding cannot occur when the methods have different return types or {{throws}} clauses. |
Exceptions
MET11-EX0: Method hiding may occasionally be unavoidable. Declaration of hiding methods is permissible in such cases Occasionally an API will be provided that violates this rule...that is, it provides hidden methods. Invoking those methods is not a violation of this rule, provided that all invocations of hiding or hidden methods use qualified names or method invocation expressions that explicitly indicate which specific method is invoked. If the above example above had been such a case, modification of the choose()
method as shown below would have been an acceptable alternative.:
Code Block | ||
---|---|---|
| ||
public static void choose(String username) { if (username.equals("admin")) { GrantAccess.displayAccountStatus(); } else { GrantUserAccess.displayAccountStatus(); } } |
...