Skip to content

QuizNot attempted

Class fields and inheritance

When are a subclass's class fields initialised?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • Right after super() returns, before the rest of the subclass constructor
  • In a derived class, fields are defined on this right after super() returns, before the rest of the subclass constructor body runs.
  • Not before the parent constructor: this doesn't exist until the parent creates it, which is why a parent calling an overridden method sees the fields as undefined.
  • Not lazily: fields are eager per instance.
  • Not after the whole constructor: code after super() can already read them.