August 2004
Intermediate to advanced
480 pages
9h 41m
English
This is very similar to casting with primitives. But it's different. And there are some rules, young lady. Deviation will not be tolerated.
A reference of any object can be cast to a reference of type java.lang.Object.
You can cast up the class hierarchy, and down the class hierarchy. But you can't cast laterally. This means that a reference to any object O can be cast to a class reference that is a subclass of O if, when it was created, O was a subclass of that class.
You can cast up the class hierarchy automatically—that is without using the cast operator.
Object o = "some string";
Object is up the hierarchy because String extends Object. String is down the class hierarchy from Object. If you cast ...
Read now
Unlock full access