Static Variable In Java

Static Variable In Java

------->>>    If the value of a variable not varied from object to  object then it is not recommended to declared variable as instance variable as instance variable we have to declared such type of variable at class level by using  static modifier ..

------->>>  in the case of instance variable for every object a separate copy will be created but in the case of static variable a single copy will be created at class level and shared by every object of the class .

-------->>>   Static variable should be declared within the class directly but outside of any block,method or, constructor .

------->>>   Static variable will be created at the time of class loading and destroy at the time of class unloading .Hence scope of static variable is exactly same as scope of .Class File .

-------->>>   Static variable will be stored in method area ..

-------->>>>   We can access Static variables either by object reference or, class name but recommend to use class name 

-------->>>>   within the same class it is not required to   use class name and we can access directly .

------->>>>>   we can access static variables directly from both instance and static areas .

--------->>>For Static variable jvm Will provide default value and not require to initialization explicitly .

---------->>>..static variable also known as class level variable or fields .


Share this

Related Posts

Previous
Next Post »

Recent