aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Just a doubt on static methods 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 "Just a doubt on static methods" Watch "Just a doubt on static methods" New topic
Author

Just a doubt on static methods

Jas Oberai
Ranch Hand

Joined: Jan 16, 2005
Posts: 231
Hi Friends,
I have doubt on this static block:

Please explain me the explanation..friends.


SCJP 1.4 (88%)<br />SCWCD 1.4 (88%)
Joe Sondow
Ranch Hand

Joined: Apr 10, 2005
Posts: 195
In order to invoke the static main method (or any other method for that matter) the class has to be loaded in the JVM. At that point, the static variables get initialized, and the static initializer blocks execute. Creating instances of the class is not required for the static blocks to execute, and creating instances of the class will not cause the static blocks to execute again.

What's happening behind the scenes is that the JVM creates an instance of the Class class that represents the StaticTest class. There is only one Class instance for StaticTest, and that one instance is what holds all the static variables, static methods, and static initializer blocks. Creating instances of StaticTest has no effect on the sole instance of Class that holds all that static stuff relating to StaticTest.


SCJA 1.0 (98%), SCJP 1.4 (98%)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Just a doubt on static methods