Skip to main content

Practice · 1 of 3

Predict the initialization sequence

CHALLENGE
Difficulty: advanced+25 XP

Implement static List<String> trace() that returns the exact observable initialization order for new Derived() in this class family: 1. class Base { Base() { t("Base ctor"); } } where t records into the trace. 2. class Derived extends Base { static String S = t("D static"); int x = t("D field"); Derived() { t("D ctor"); } } Rules: t appends to a shared list and returns its argument. trace() creates one Derived and returns the recorded list. Static init happens at first active use — instantiation counts.

Back to lesson: Practice: Object model drills