Java Reference
In-Depth Information
Here, even though class X and class Y are structurally the same, it is not possible to assign
an X reference to a Y object because they have different types. In general, an object refer-
ence variable can refer only to objects of its type.
There is, however, an important exception to Java's strict type enforcement. A reference
variable of a superclass can be assigned a reference to an object of any subclass derived
from that superclass. In other words, a superclass reference can refer to a subclass object.
Here is an example:
Search WWH ::




Custom Search