Yes. The method just returns a reference to the String
itself.
No new object is created.
import java.awt.*;
class PointEg3
{
public static void main ( String arg[] )
{
Point a = new Point(); // declarations and construction combined
Point b = new Point( 12, 45 );
Point c = new Point( b );
System.out.println( a ); // create a temporary String based on "a", print it out
System.out.println( b ); // create a temporary String based on "b", print it out
System.out.println( c ); // create a temporary String based on "c", print it out
}
}
The example program has been changed, yet again. The program prints out:
java.awt.Point[x=0,y=0]
java.awt.Point[x=12,y=45]
java.awt.Point[x=12,y=45]
This program is deceptively short. However, its execution calls for quite a bit of activity.
Just as the program is about to close, how many objects have been created?
How many object references are there?
Has any garbage been created?