E07060: 'override' is not required on a constructor

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

What went wrong

You've marked a constructor with 'override', but constructors don't participate in method overriding - each class defines its own constructors.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 775 (Why can't a constructor use the override keyword in EK9?)

How to fix it

  1. Remove 'override' from constructor
  2. Use super() to call parent constructor
  3. Constructors are independent in each class

Common causes

  • Confusion about constructor inheritance
  • Copy/paste from regular method
  • Misunderstanding override semantics

See also

  • E07060: override constructor (this error)
  • E07050: abstract constructor
  • E07010: private with override (method)

Examples

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

Fails with E07060: 'override' is not required on a constructor

#!ek9
defines module error.e07060.bad

  defines class

    Base as open
      default Base()

    Derived extends Base

      //Constructors are never inherited, so there is nothing to override
      override Derived()
        super()

Fixed: Remove 'override' from the constructor

#!ek9
defines module error.e07060.good

  defines class

    Base as open
      default Base()

    Derived extends Base
      Derived()
        super()

Questions and answers

These Q&A entries show E07060 and its fix: