File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static Member Initialization

 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 317
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic