O'Reilly logo

Java All-in-One For Dummies, 4th Edition by Doug Lowe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3

Working with Statics

In This Chapter

arrow Adding static fields to a class

arrow Creating static methods

arrow Creating classes that can be instantiated

arrow 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.

Understanding 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required