strArray[0] = "Good-by" ;
This will replace the reference in cell 0 with a reference to
a new String, containing the characters "Good-by" .
String[] args
Each cell of an array of object references works just like an ordinary
object reference variable.
In the question, strArray[0] starts out with a reference to one
String, then is assigned a reference to another.
The previous String is now garbage.
Here is the familiar signature of the
main()
method:
public static void main( String[] args )
The phrase
String[] args
says that
main()
has a parameter which is a reference to an array of String references.
This array is constructed by the Java system
just before
main()
gets control.
The elements of the array refer to Strings
that contain text from the command line that starts the program.
For example, say that a program is started with this command line:
C:\>java StringDemo stringA stringB stringC
The picture shows what the parameter args looks
like while
main()
is running.
What would the following statement print, given the above picture?
System.out.println( args[0] );