Question 0-2

What distinguishes the purpose of a class variable from an instance variable? I am not asking how they are syntactically distinguished in Java. (In Java, an instance variable is declared directly inside the class. A class variable is also, but it additionally includes the static keyword.)

Solution

A class variable is at a fixed location in memory. There can only be one copy of it available at any time. An instance variable, on the other hand, is associated with each individual instance of the class.

Back to Midterm 0