Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

static variables intialization  RSS feed

 
kundan varma
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
When does static variables of a class actually get initialized? Is it at the time of class instantiation or at the time of class loading ?

THanks
kundan
 
Sanat Padhy
Greenhorn
Posts: 6
Java Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static variables are initialized during class loading. It's not required to create an instance of the class to access a static variable.
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kundan,
We can use static variable although we don't initialize that class.
And that value is initialized when the class is loaded.

Example


Correct me if I am wrong
Hope this help...

daniel
 
kundan varma
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THanks sanat and fisher
Your replies were helpful.
Thanks
kundan
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!