TYPES, VALUES, AND VARIABLES
Variables Have Types, Objects Have Classes
4.5.5
The example program:
class Point {
static int npoints;
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);
}
}
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 prepared ( 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, linking, and initialization of classes and interfaces, plus a
description of the instantiation of classes to make new class instances.
4.5.5   Variables Have Types, Objects Have Classes
Every object belongs to some particular class: the class that was mentioned in the
creation expression that produced the object, the class whose class object was
used to invoke the
newInstance
 method ( 20.3.6) to produce the object, or the
String
 class for objects implicitly created by the string concatenation operator
+
( 15.17.1). This class is called the
class of the object
. (Arrays also have a class, as
described at the end of this section.) An object is said to be an instance of its class
and of all superclasses of its class.
(Sometimes a variable or expression is said to have a  run time type  but that
is an abuse of terminology; it refers to the class of the object referred to by the
value of the variable or expression at run time, assuming that the value is not
null
. Properly speaking, type is a compile time notion. A variable or expression
has a type; an object or array has no type, but belongs to a class.)
The type of a variable is always declared, and the type of an expression can be
deduced at compile time. The type limits the possible values that the variable can
hold or the expression can produce at run time. If a run time value is a reference
47






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

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