Class Variables
class variable
is a value in a class that is common to all instances of that class.
There is only 1 of these class variables, even when multiple objects
have been declared.
Every instance of the class can reference and change this value.
A class variable has the keyword
static
in its declaration:
static String lastName = "Bishop";
You can reference a class variable using either syntax:
object.classVariable
Class.classVariable
However, you should use the class name instead of the instance name so it is
clear when your code is referencing a class variable and when it is referencing
an instance variable.
Where have we already seen a class variable?
Why is is a class variable; i.e. why is there only 1 of them?