Forums Register Login

Cyclic class

+Pie Number of slices to send: Send

i found this code in some site.
pls explain what happen
+Pie Number of slices to send: Send
Well the answer is in the behaviour of Classloader/Intilization.
JLS: A class/interface is initialized when either its static variable/method is called for the first time, in the above case when the C is used in the main method the initilizer tries to initilize the C it reaches line int C= which uses interfaceA so it will try to initilize A when it reaches A= it uses B= so it initilize B it reaches B= which uses C again as C is in mid of initilization if a variable is used in mid of initilization the default value is returned its similar to using a variable of a subclass in super class constructor. Hence the the value returned for int B= 0 + 1 and rest is calcuated, but when the control comes to the main method the interfaceC is fully intilized it can now get value of C.
Hope this answered your question.
LOOK! OVER THERE! (yoink) your tiny ad is now my tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 713 times.
Similar Threads
Why public?
Can't understand the Output
How the Interface works ?
Please tell me the program flow..
deadly diamond of death syndrome :)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 15:00:24.