On this page
  1. static
  2. Availability
  3. Syntax & Overview
  4. Notes & Pitfalls
  5. Example

static

Prev: `final` | Up: builtins | Next: `try with resources`
Rel: builtins, Classes, Records & Sealed Hierarchies
Ref: Java Docs — static
Tags: #public #prog #java #builtins #tier/core


Availability

Built-in / java.lang (Language Modifier) — available with zero import statements.

Syntax & Overview

public static int add(int a, int b) { return a + b; }

Binds a field, method, or nested class to the class itself rather than an instance.

Notes & Pitfalls

Example

class Counter {
    static int next = 0;
    static int bump() { return ++next; }
}
assert Counter.bump() == 1;

Linked from

Related notes