I was going through Learning the
java language Trail from official java tutorials. The below two topics teaches to use objects
Referencing an Object's Fields
and
Calling an Object's Methods
In the first topic the below code doesn't keep the reference to the object that got created.
int height = new Rectangle().height;
The explanation given for the above code is below:
"After this statement has been executed, the program no longer
has a reference to the created Rectangle, because the program never stored the reference anywhere."
Below is the example of second topic:
int areaOfRectangle = new Rectangle(100, 50).getArea();
In the above sentence does the object reference gets stored somewhere and why?