Friday, 29 April 2016

Order in Initialization

Do you know what the following piece of code will print?




The answer is:

MyClass
Parent
MyClass
Test

Now can you tell which instance (instance1 or instance2) prints the first "MyClass" string?
 
Uncomment the commented lines and see for yourself!

http://stackoverflow.com/questions/14805547/are-fields-initialized-before-constructor-code-is-run-in-java

http://stackoverflow.com/questions/17806342/order-of-constructor-calls-in-multilevel-inheritance-in-java

1 comment:

javaGirl said...

Post number 100!