Access rules when overriding methods

A class Account declares three methods: protected double fee(), public String id() and private void audit(). The class SavingsAccount extends Account is in the same package, and it declares its own fee(), id() and audit() with the same signatures. Fill in each blank with one word.


Because fee() is protected in Account, the overriding fee() in SavingsAccount may be declared protected or . Because id() is public in Account, its override must be declared .


If SavingsAccount declares fee() with no access modifier, the result is a compile-time , even though both classes are in the same package. Because audit() is private, SavingsAccount does not it, so the audit() in SavingsAccount is a new, separate method and may use any access level.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Access Modifiers Questions: