Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added quote

...

Code Block
bgColor#ccccff
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");	
  }
}

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 are new methods, unique to the subclass." Tutorials 08

Risk Assessment

Confusing overriding and hiding can produce unexpected results.

...