as far as i know it's not possible to cast an Object of a superclass into an Object of a subclass. This will compile but during runtime it will return an error.
More specifically, given the following Hierarchy of Classes and Interfaces:
. Alpha is a superclass for Beta and Gamma
. Gamma is a superclass for Delta and Omega
. Interface "In" is implemented by Beta and Delta
In this scenario i define the following code:
Delta r;
Gamma q;
Is this correct?
r = (Delta) q;
Can i cast q to type Delta even if Delta is a subclass of Gamma? I think this isn't possible, my text book says otherwise. I already searched a lot and according to this i'm right and this is an error from the textbook.
Am i missing anything?