5.7 Static Variables and Methods
Enduring Understanding
Programmers use code to represent a physical object or nonphysical concept, real or imagined, by defining a class based on the attributes and/or behaviors of the object or concept.
Learning Objective
Define behaviors of a class through static methods.
Essential Knowledge
Static methods are associated with the class, not objects of the class.
Static methods include the keyword static in the header before the method name.
Static methods cannot access or change the values of instance variables.
Static methods can access or change the values of static variables.
Static methods do not have a this reference and are unable to use the class’s instance variables or call non-static methods.
Learning Objective
Define the static variables that belong to the class.
Essential Knowledge
Static variables belong to the class, with all objects of a class sharing a single static variable.
Static variables can be designated as either public or private and are designated with the static keyword before the variable type.
Static variables are used with the class name and the dot operator, since they are associated with a class, not objects of a class.
Last updated
Was this helpful?