Language syntax

Java Static field

Class-level state shared by instances of the defining class; does not automatically make updates thread safe.

Formal Syntax & Structure

java syntaxjava
static Type fieldName;

Working Example

Example Snippetjava
class Counter {    private static int created;    private int clicks;    Counter() { created++; }    void click() { clicks++; }    int clicks() { return clicks; }    static int created() { return created; }}public class Main {    public static void main(String[] args) {        Counter a = new Counter();        Counter b = new Counter();        a.click();        a.click();        System.out.println(a.clicks());        System.out.println(b.clicks());        System.out.println(Counter.created());    }}
Java Reference