The reason 40 is printed when the A() constructor calls print is that the compiler *hard-codes* the print statement to print 40. However, at that moment, the variable d is still 0.
(1) the compiler hard codes the constant when it is referenced (as expected) and (2) the variable is actually allocated space in the object and is assigned a value.
Originally posted by Marlene Miller:
Yi Meng, was your question answered? Would you like a shorter, more concise answer?