What would be the output of this code snippet?
The output is:
derived base derived base
That might appear as a surprising behavior for a class variable, which is in general shared between all derived classes. But the trick here is that the class variable
var has been set in the child first (and not in the parent first). The implication is that the parent and child classes end up with their own independent class variable (with identical names).
Credit: this is trick #19 from a nice list from Auckland University, New Zealand.