E07010: remove 'override' with use of 'private' access modifier

Category: E07xxx Full resolution · Reported in phase: SYMBOL_DEFINITION · Classification: METHOD_ACCESS_MODIFIER_PRIVATE_OVERRIDE · All error codes

What went wrong

You've marked a PRIVATE method with 'override', but private methods cannot override anything - they are invisible to subclasses.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 573 (What are the access modifier rules for method overrides?)
  • ek9 -q 676 (How do override and access modifiers interact in a three-...)

How to fix it

  1. Remove 'override' if this is a new private method
  2. Change to protected/public if it should truly override
  3. Private methods are always independent in each class

Common causes

  • Method was public, got changed to private, 'override' left behind
  • Copy/paste from non-private method
  • Misunderstanding private visibility

See also

  • E07010: private with override (this error)
  • E07020: abstract with override (also contradictory)

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E07010: remove 'override' with use of 'private' access modifier

#!ek9
defines module error.e07010.bad

  defines class

    Account as open
      private auditCode()
        <- rtn as String: "A"

    Savings extends Account

      //A private method cannot override, and a private parent method cannot be overridden
      override private auditCode()
        <- rtn as String: "S"

Fixed: Override a visible method, and drop private

#!ek9
defines module error.e07010.good

  defines class

    Account as open
      auditCode()
        <- rtn as String: "A"

    Savings extends Account
      override auditCode()
        <- rtn as String: "S"

Questions and answers

These Q&A entries show E07010 and its fix: