Skip to Content
Learn
Static Variables and Methods
Review

Great work! You now have an understanding of what the static keyword does. In fact, if you’ve made it this far in your Java lessons, you probably have a pretty good sense of what all the keywords and jargon are doing in public static void main(String[] args). Take a moment to celebrate — that line of code can be incredibly intimidating for new learners and it’s a real accomplishment to learn about all of those different pieces.

To review, here are some of the main takeaways about static methods and variables:

  • Static methods and variables are associated with the class as a whole, not objects of the class.
  • Static methods and variables are declared as static by using the static keyword upon declaration.
  • Static methods cannot interact with non-static instance variables. This is due to static methods not having a this reference.
  • Both static methods and non-static methods can interact with static variables.

Instructions

We’ve given you the complete code for your ATM class. Feel free to experiment with these static variables and methods. In particular, you might want to create a few more ATMs in the main() method and see how the static variables change. You could also consider writing a depositMoney() method that works in the opposite way as withdrawMoney().

Folder Icon

Take this course for free

Already have an account?