Skip to main content

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

Back to lesson: Practice: Object model drills