Hi,
Welcome to the forum! 
You can actually use what is called “class variables” by using the static keyword when declaring a member variable in your class.
Like this :
class BubbDraw {
static int count = 0;
}
For example we declare a count variable with static that is then going to be shared among all the instances of the BubbDraw class.
That means that it’s initialized once when the class is interpreted and then all the BubbDraw objects can access it :
class BubbDraw {
static final int count = 0;
}
BubbDraw b1 = new BubbDraw();
println(b1.count); // -> 0
BubbDraw b2 = new BubbDraw();
b2.count = 2;
println(b2.count); // -> 2
println(b1.count); // -> 2
// Also accessible with the class name if declared public/package
println(BubbDraw.count); // -> 2
The bad news is that when coding in the Processing IDE, the code you write is wrapped inside a PApplet class so you can’t actually use non final static class variables.
This is for example the exported code :
import processing.core.*;
import processing.data.*;
import processing.event.*;
import processing.opengl.*;
import java.util.HashMap;
import java.util.ArrayList;
import java.io.File;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
public class testStatic extends PApplet {
public void setup() {
class BubbDraw {
static final int count = 0;
}
noLoop();
}
static public void main(String[] passedArgs) {
String[] appletArgs = new String[] { "testStatic" };
if (passedArgs != null) {
PApplet.main(concat(appletArgs, passedArgs));
} else {
PApplet.main(appletArgs);
}
}
}
But in Java you can’t have a static declaration in an inner class :
In Processing, you get this error :
The field count cannot be declared static in a non-static inner type, unless initialized with a constant expression
The solution is to use Eclipse or configure a real Java project so you can use the full power of OOP with Processing.
But a workaround is also to declare the class static :
static class BubbDraw {
static int count = 0;
}
void setup() {}
(note that it does not work when there’s no setup() function
)