What is difference between instance variable and static variable?


Instance Variable
Static variable
1.      Variable which are declared inside the class without static keyword are called as instance variable or reference variable.
2.      Memory is allocated during the creation of object.
3.      Multiple copy of memory will be allocated for instance variable.
1.      Variable which are declared inside the class with static keyword are called static variable.
2.      Memory will be allocated for static variable when JVM is loading the class into main memory.
3.      Only one copy of memory will be allocated for static variable.

0 comments :

Post a Comment