This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

Name

static

Examples
void setup() {
  MiniClass mc1 = new MiniClass();
  MiniClass mc2 = new MiniClass();
  println( mc1.y );   // Prints "10" to the console
  MiniClass.y += 10;  // The 'y' variable is shared by 'mc1' and 'mc2'
  println( mc1.y );   // Prints "20" to the console
  println( mc2.y );   // Prints "20" to the console
}

static class MiniClass {
  static int y = 10;  // Class variable
}

void setup() {
  println(MiniClass.add(3, 4));  // Prints "7" to the console
}

static class MiniClass {
  static int add(int x, int y) {
    return(x + y);
  } 
}
Description Keyword used to define a variable as a "class variable" and a method as a "class method." When a variable is declared with the static keyword, all instances of that class share the same variable. When a class is defined with the static keyword, it's methods can be used without making an instance of the class. The above examples demonstrate each of these uses.

This keyword is an essential part of Java programming and is not usually used with Processing. Consult a Java language reference or tutorial for more information.
Updated on July 4, 2018 11:56:48am EDT

Creative Commons License