© Vaskaran Sarcar 2020
Vaskaran SarcarInteractive Object-Oriented Programming in Javahttps://doi.org/10.1007/978-1-4842-5404-2_8

8. Understanding Class Variables and Class Methods

Vaskaran Sarcar
Bangalore, Karnataka, India
Sometimes developers do not want to operate through instances of a type. Instead, they prefer to work on the type itself. The concept of class variables or class methods appears in these scenarios. They are commonly known as static variables or static methods .
Let’s consider a case where you want a variable to be shared among all objects of a class regardless of how many objects are created from the class. Other times, you may also want to maintain a single copy to handle some specific scenarios; for example, when you maintain ...

Get Interactive Object-Oriented Programming in Java: Learn and Test Your Programming Skills now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.