IN THIS CHAPTER
Adding static fields to a class
Creating static methods
Creating classes that can be instantiated
Working with static initializers
Astatic method is a method that isn’t associated with an instance of a class. (Unless you jumped straight to this chapter, you already knew that.) Instead, the method belongs to the class itself. As a result, you can call the method without first creating a class instance. In this chapter, you find out everything you need to know about creating and using static fields and methods.
According to my handy Webster’s dictionary, the word static has several meanings, most of which relate to the idea of being stationary or unchanging. A static display is a display that doesn’t move. Static electricity is an electrical charge that doesn’t flow. A static design is a design that doesn’t change.
As used by Java, however, the term static doesn’t mean unchanging. You can create a static field, for example, and then assign values to it as a program executes. Thus, the value of the ...