Course contentsShow
← Computer Science
Lesson 2130 of 2,87248. Programming ParadigmsFree lesson

Static Members and Class Methods

Distinguish between instance members tied to objects and static members shared across all instances of a class.

Static Members and Class Methods

You'll learn how to distinguish between members tied to individual objects and those shared by the entire class.


When you create multiple objects from a class, each object typically gets its own copy of instance variables and can call instance methods that operate on that specific object's data. But sometimes you want data or behavior that belongs to the class itself, not to any particular instance.

Static members (also called class members) are shared across all instances of a class. Instead of each object having its own copy, there's exactly one copy that all objects can access.

Instance Members (What You Already Know)

When you create a BankAccount object, each account has its own balance and accountNumber. These are instance variables. Instance methods like deposit() operate on the data of one specific account.

Static Members (The New Concept)

Suppose you want to track the total number of bank accounts created. You don't want each account to store this count separately—that would be redundant and error-prone. Instead, you declare a static variable that belongs to the BankAccount class itself. Every time any constructor runs, it increments this shared counter.

Similarly, static methods (class methods) don't operate on a specific object's data. They might perform utility operations or access static variables. You call them using the class name, not an object reference.

Why It Matters

Static members let you model "class-level" properties and behaviors—things that apply to the blueprint itself, not individual instances. Think of instance members as "what each person owns" and static members as "what the community shares."

Key Takeaway:
Instance members belong to individual objects; static members are shared by the class and exist independently of any particular instance.