Demo
class
public class Demo
{
public static void main(String[] args)
{
Coordinate2D c1 = new Coordinate2D(5, 6);
/* paused here */
/* code not yet run */
}
}
The Coordinate2D
constructor finishes executing. The new
keyword returns the memory address of the newly created object/instance.
The left side of assignment operator executes next. The code Coordinate2D c1
creates a variable of type Coordinate2D
named c1
.
The assignment operator (=
) sets the value of c1
to the memory address of the newly created object.
Memory diagram
The memory address of the object is represented as an arrow. It is common to say that c1
refers/points to the object.
Parameters initX
and initY
no longer exist, since the constructor is no longer executing.