Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

static variables and methods

  Asked By: Viveka    Date: Mar 24    Category: Java    Views: 752
  

** if static variables are initialised at compile time then how do
they got a
space in callstack in jvm.
** if my class was compiled ten days before then still i attain a
initialised
value of that variable.
** a compiler and a jvm has no relation related to memory then how
static
variables are transfered from compile time initialisation to runtime

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Erin Dunn     Answered On: Mar 24

They are not initialised at compile  time. They are initialised at
runtime, when the class  is loaded. The compiler  only adds the expression
to initialize the static  variable, in the .class file. For a primitive,
this can be a literal, like in 'int i=5;', so then there would be 4
bytes in the .class file that hold the integer value 5, and that will be
assigned to i when the class is loaded (or just after the class is loaded).

 
Didn't find what you were looking for? Find more on static variables and methods Or get search suggestion and latest updates.




Tagged: