You first write a "class", which tells the computer what the object is and what it does. For instance, lets say we want to create a lot of balls. Each ball will have an x and y location. So we can write a class for a ball like this:
Everything in the curly brackets will belong to a ball.
Now, we can create a ball by using the "new" keyword, like this:
- Ball b = new Ball();
We now have a new Ball. This ball has its own x and y variables that we specified earlier, when we wrote the class. We can get to the variables by putting a dot between the name of the ball and the name of a variable, like this:
- b.x = 10;
- println(b.x);
In the first line we set the ball's x coordinate to be 10. In the second line we print out the ball's coordinate. It's just like using normal variables.
Here's where I answer your question: We can create more than one Ball by just writing "new" again. For instance:
- Ball b1 = new Ball();
- Ball b2 = new Ball();
- Ball b3 = new Ball();
- b1.x = 10;
I've created three balls. Each one of them has its own x and y position. I set the x position of the first ball to be 10; only that ball's variable has changed.
Does that help?