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 first String
is now garbage.
Here is the familiar signature of the
main()
public static void main( String[] args )
The phrase
String[] args
main()
String
references.
This array is constructed by the Java system
just before
main()
String
s
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()
What would the following statement print?
System.out.println( args[0] );