Java Reference
In-Depth Information
int x, y;
Point root;
}
class Test {
public static void main(String[] args) {
System.out.println("npoints=" + Point.npoints);
Point p = new Point();
System.out.println("p.x=" + p.x + ", p.y=" + p.y);
System.out.println("p.root=" + p.root);
}
}
This program prints:
npoints=0
p.x=0, p.y=0
p.root=null
illustrating the default initialization of npoints , which occurs when the class Point is pre-
pared (§ 12.3.2 ), and the default initialization of x , y , and root , which occurs when a
new Point is instantiated. See §12 for a full description of all aspects of loading, link-
ing, and initialization of classes and interfaces, plus a description of the instantiation
of classes to make new class instances.
4.12.6. Types, Classes, and Interfaces
In the Java programming language, every variable and every expression has a type that can
be determined at compile time. The type may be a primitive type or a reference type. Refer-
ence types include class types and interface types. Reference types are introduced by type
declarations , which include class declarations (§ 8.1 ) and interface declarations (§ 9.1 ) . We
often use the term type to refer to either a class or an interface.
In the Java Virtual Machine, every object belongs to some particular class: the class that
was mentioned in the creation expression that produced the object (§ 15.9 ), or the class
whose Class object was used to invoke a reflective method to produce the object, or the
String class for objects implicitly created by the string concatenation operator + 15.18.1 ) .
This class is called the class of the object . An object is said to be an instance of its class
and of all superclasses of its class.
Every array also has a class. The method getClass , when invoked for an array object, will
return a class object (of class Class ) that represents the class of the array 10.8 ).
The compile-time type of a variable is always declared, and the compile-time type of an
expression can be deduced at compile time. The compile-time type limits the possible val-
Search WWH ::




Custom Search