aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Cyclic class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Cyclic class" Watch "Cyclic class" New topic
Author

Cyclic class

Weerawit Maneepongsawat
Ranch Hand

Joined: Apr 11, 2002
Posts: 203

i found this code in some site.
pls explain what happen


Weerawit<br />SCJP 1.4, SCWCD 1.2, SCWCD 1.4, SCBCD 1.3, SCBCD 5.0, SCMAD 1.0, SCJA 1.0, SCDJWS, SCJD, SCEA, SCDJWS 1.5
Lawrence Chettiar
Ranch Hand

Joined: Apr 10, 2003
Posts: 62
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.


SCJP 1.4 (86%)<br />SCMAD Beta (77%)<br />SCEA (part I:89%,partII:93%)<br />MCAD (cleared 70-315 & 70-320 [Score 980])
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cyclic class