Practice ยท 1 of 3
Predict the initialization sequence
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.
Difficulty: advanced
Press Submit to check your solution.
Back to lesson: Practice: Object model drills