This content has been marked as final. Show 4 replies
That the value is set when the class is loaded.
class is loaded ---------from where to where it is loaded
Hey here is a great help
A static variable is intilized when the class is loded. Which means that
the static variable will have the same value regardless of the number of
objects we create from that class. And the value of that static variable is the same in all objects of that class.
Example let say there is a static variable x in class animal
lets say we create an object called cat from the class animal and also an object dog.
the value of the vairable x is the same in both cat and dog always.
if we make
then the x in dog will also be 9.
Hence, static variables can be used to share a common information
between objects of the same class. For example the number of legs is
common to both cats and dogs
the value of the vairable x is the same in both catAnd the whole point is: static variables are not related to class's objects, and they are not supposed to be accessed through an object reference.
and dog always.
if we make
dog will also be 9.