...
Code Block |
---|
|
class GrantAccess {
public static void displayAccountStatus() {
System.out.print("Account details for admin: XX");
}
}
class GrantUserAccess extends GrantAccess {
public static void displayAccountStatus() {
System.out.print("Account details for user: XX");
}
}
public class StatMethod {
public static void choose(String username) {
if(username.equals("admin"))
GrantAccess.displayAccountStatus();
else
GrantUserAccess.displayAccountStatus();
}
public static void main(String[] args) {
choose("user");
}
}
|
Wiki Markup |
---|
Note that "In a subclass, you can overload the methods inherited from the superclass. Such overloaded methods neither hide nor override the superclass |
methodsâ”they methodsâthey are new methods, unique to the subclass." \[[Tutorials 08|AA. Java References#Tutorials 08]\] |
Risk Assessment
Confusing overriding and hiding can produce unexpected results.
...