Static Variables and Methods

Caleb Thomas
6 min read
Listen to this study note
Study Guide Overview
This study guide covers static variables and static methods in Java. It explains their association with the class itself, not individual objects. Examples using the Student
class demonstrate adding and using static members like grade boundaries and school name. The guide also shows how to access static members using the class name and dot operator (e.g., Student.setSchool()
).
We are almost done with our classes, with only two more rounds of edits to make, one in this topic and the next in Topic 5.9. First, we will need to learn more about static variables and methods.
#Introduction to Static Variables and Methods
Static variables and methods are marked by the keyword static, which means that these are properties of the entire class and not just of one particular object. For example, static variables and methods are for things that are true for every student, such as boundaries for certain letter grades which we will implement in Topic 5.9, and also the school that the student goes to, which we will implement in this Topic.
Another example of static variables and methods is the Math class we learned back in Unit 2. There are no separate "math objects," but every method is just a general math method doing a calculation.
It is important to note:
- Static methods cannot access or change the values of instance variables.
- Static methods do not have a this reference (which we will talk about in Topic 5.9) and cannot use instance variables or call non-static methods.
- However, static methods can access or change the values of static variables.
#Adding Static Variables and Methods
We will add static variables and methods to our Student class. Here is a summary of what we will add: grade boundaries for letter grades, a method to get t...

How are we doing?
Give us your feedback and let us know how we can improve