Class Variables
Besides instance variables, a class may contain “global variables” that are not associated with any instance.
A class variable is flagged by the static modifier in its declaration:
class Potato {
public String name;
static public int num = 0 ;
// Class variable—number of potatoes.
}
Potato p = new Potato(), q = new Potato() ;
p.name = “one potato” ;
q.name = “two potato” ;
Potato.num += 2 ; // static field prefix is class name.