Skip to content
Justice Tech School

static Fields and Methods

static members belong to the class, not to objects.

Example
public class Main {
  static class Counter { static int count; Counter() { count++; } }
  public static void main(String[] args) {
    new Counter(); new Counter();
    System.out.println(Counter.count);
  }
}

Result

2

Exercise

Class level field.

 int count;

Quiz Test

Where is a static field stored?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.