What’s the difference between a class variable and an instance variable?
?
?
Knowing the terminology is important. Instance variables and class variables are both member variables. They are both member variables because they are both associated with aspecificclass. But, there are differences between instance variables and class variables.
Instance variables belong to an instance of a class. Another way of saying that is instance variables belong to an object, since an object is an instance of a class. Every object has it’s own copy of the instance variables. Here is what a declaration of an instance variable would look like: