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:
• Field access, using either a qualified name (§ 6.6 ) or a field access expression
15.11 )
• Method invocation (§ 15.12 )
• The cast operator (§ 5.5 , § 15.16 )
• The string concatenation operator + 15.18.1 ) , which, when given a String operand
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
• The instanceof operator (§ 15.20.2 )
• The reference equality operators == and != 15.21.3 )
• The conditional operator ? : 15.25 ) .
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
Search WWH ::




Custom Search