Sometimes it helps to use examples that are more concrete, making it a bit easier to understand.
<code>
<pre>
class Pet {}
class Dog extends Pet {}
class Cat extends Pet {}
public class ExtendsTest{
public static void main(String args[])
{
Pet generic = new Pet();
Dog fido = new Dog();
Cat felix = new Cat();
// insert statement here
}
}
(a) generic=fido;
(b) felix=generic;
(c) fido=(Dog)generic;
(d) felix=(Cat)fido;
(e) fido=(Pet)fido;
</pre></code>
Your answer for (d) is correct. They have no inheritance relationship. They are siblings of the super class and siblings cannot be assigned to each other, even with a cast. As above, it doesn't make much sense to cast a dog object into a cat object.
I don't see the benefit of upcasting an object, then downcasting to the original object. But it is legal. This is not the case with primitives. If you cast a double to an int and then back to a double, information is lost.
[This message has been edited by Jim Hall (edited November 30, 2001).]