Creating an Object
Painter alice = new Painter ();
- ”Painter” specifies the class, or type of object we want
- ”alice” gives a name for the object that we can reference. The name can be whatever you choose! You should try to use names that are easy to recognize
- ”new” is the keyword that tells Java we want a new object
- ”Painter” class the constructor in the “Painter” class to create the “Painter” object.
When we instantiate an object, we are creating an instance of the class. We can create multiple instances of a class.
When we create a Painter object, it starts at (0, 0) facing East with 0 units of paint by default. This is because of the instructions given in the Painter() constructor.