4.3.2
The Class
Object
TYPES, VALUES, AND VARIABLES
The example program:
class Value { int val; }
class Test {
public static void main(String[] args) {
int i1 = 3;
int i2 = i1;
i2 = 4;
System.out.print("i1==" + i1);
System.out.println(" but i2==" + i2);
Value v1 = new Value();
v1.val = 5;
Value v2 = v1;
v2.val = 6;
System.out.print("v1.val==" + v1.val);
System.out.println(" and v2.val==" + v2.val);
}
}
produces the output:
i1==3 but i2==4
v1.val==6 and v2.val==6
because
v1.val
and
v2.val
reference the same instance variable ( 4.5.3) in the
one
Value
object created by the only
new
expression, while
i1
and
i2
are differ
ent variables.
See 10 and 15.9 for examples of the creation and use of arrays.
Each object has an associated lock ( 17.13), which is used by
synchronized
methods ( 8.4.3) and the
synchronized
statement ( 14.17) to provide control
over concurrent access to state by multiple threads ( 17.12, 20.20).
4.3.2 The Class
Object
The standard class
Object
is a superclass ( 8.1) of all other classes. A variable of
type
Object
can hold a reference to any object, whether it is an instance of a class
or an array ( 10). All class and array types inherit the methods of class
Object
,
which are summarized here and completely specified in 20.1:
package java.lang;
public class Object {
public final Class getClass() {
. . .
}
public String toString() {
. . .
}
public boolean equals(Object obj) {
. . .
}
public int hashCode() {
. . .
}
protected Object clone()
throws CloneNotSupportedException {
. . .
}
40
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved