Skip to main content
PreparationZone Logo
PreparationZone
Back to Fundamentals

Fundamentals · Medium · Free

What does static mean for variables and methods?

FresherFundamentalsOOP & Language Fundamentals
Model answer

static members

static belongs to the class, not each instance—one copy shared by all objects. Static methods cannot access instance fields directly.

  • static fields: counters, caches, constants (with care for thread safety).
  • static methods: utilities (Math.max)—no this.
  • Static blocks run once when class loads.
java
class IdGenerator {
  private static int next = 1;
  static int nextId() { return next++; }
}
Warn about static mutable state in web apps—hard to test and breaks in clustered servers.