References
are sort of pointers to a block of memory called objects.
GUI g1 = new GUI();
For explanation, let me break the above statement.
GUI g1;
g1 = new GUI();
1st step: g1
is a reference variable (pointer), not yet pointing to any valid memory location.
2nd Step: The second step allocates the memory for object of class GUI
and the assignment operation make the reference variable g1
point to this object (memory location).
The new
keyword allocates the memory for the object of class GUI
.