Java Reference
In-Depth Information
p = (Point)Class.forName("Point").newInstance();
} catch (Exception e) {
System.out.println(e);
}
/* An array is implicitly created
by an array constructor: */
Point a[] = { new Point(0,0), new Point(1,1) };
/* Strings are implicitly created
by + operators: */
System.out.println("p: " + p);
System.out.println("a: { " + a[0] + ", " + a[1] + " }");
/* An array is explicitly created
by an array creation expression: */
String sa[] = new String[2];
sa[0] = "he"; sa[1] = "llo";
System.out.println(sa[0] + sa[1]);
}
}
This program produces the output:
default
p: (0,0)
a: { (0,0), (1,1) }
hello
The operators on references to objects are:
• Method invocation (§
15.12
)
and a reference, will convert the reference to a
String
by invoking the
toString
meth-
od of the referenced object (using
"null"
if either the reference or the result of
toString
is a null reference), and then will produce a newly created
String
that is the
concatenation of the two strings
There may be many references to the same object. Most objects have state, stored in the
fields of objects that are instances of classes or in the variables that are the components of