(2)The variable dog is pointing to a Dog object and you want to cast this to an o object (horrible name by the way), but a Dog is not an o, therefore this is not possible and you get a ClassCastException. (3)Same reason, a dog is not an o, therefore you can not just assign it to O. (1)It compiles because it could have worked. When the dog variable would have been pointing to an o object, it would have been fine. (because an o is a Dog)

Try replacing the line

with

and see what happens.

You seem a little confused by the fact that an o is also a Dog, but a Dog is not an o. [ September 27, 2007: Message edited by: bart zagers ]