Java Reference
In-Depth Information
If the declared (i.e., static) type of variable
veh
is
Vehicle
and
Car
is a subclass of
Vehicle
,
then this statement will compile. A separate check is made at runtime to ensure that the object
referred to by
veh
really is a
Car
and not an instance of a different subtype.
It is important to appreciate that casting between object types is completely different from cast-
ing between primitive types (Section B.2, above). In particular, casting between object types
involves
no change
of the object involved. It is purely a way of gaining access to type informa-
tion that is already true of the object—that is, part of its full dynamic type.
Search WWH ::
Custom Search