0
What is the difference between static variables and instance variables??
Why static variables are called class variable?. Why non static variables are stored in object memory? https://code.sololearn.com/c0Szxm9cnD11/?ref=app
4 ответов
+ 4
Expanding on peter's answer...
Static members are bound to the class type which exists once per process.
Instance members are bound to an object instance of a class type and apply to their respective object instances.
+ 3
We do not need to create object to use static members ( fields or methods ). For example, Its useful when we need to count how many instances of certain class was made.
+ 1
one belong to the instance of a class, thus an object. And every instance of that class (object) has it's own copy of that variable. Changes made to the variable don't reflect in other instances of that class.
class variables well these are also known as static member variables and there's only one copy of that variable that is shared with all instances of that class. If changes are made to that variable, all other instances will see the effect of the changes.
0
It's about scope and efficient memory management. Static variables can be accessed anywhere independent of any object.