aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static Member Initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Static Member Initialization" Watch "Static Member Initialization" New topic
Author

Static Member Initialization

Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 771
Hello All,

This piece of code is taken from k&B book chapter 2.



My question is this, as static variables are class variables. So when class is loaded in JVM, then value of s is initialized to alpha subsub.
Or when the constructor of SubSubAlpha() is created?

Thanks,


Prithvi/Beenish,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 819

not when class is loaded into JVM.

the constructor for the super class runs first.

so s is first set to "alpha" by the constructor in Class Alpha

then, the constructor for SubSubAlpha runs and s ends up as "alpha subsub"

Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

When the class wil be loaded, s will be inialized to " " (space)
and will be re-initialized to "alpha subsub" when a new object of the class SubSubAlpha will be created (Line no 23).
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Try this...


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static Member Initialization
 
Similar Threads
Are questions in real exam intentionally misleading too?
Is Static veriable is visibile to subclass
some confusion about inheritance contained static.
K&B chapter 2 question 11
private constructor