posted 21 years ago
The most important thing to remember is the is a rule. For example your classes A and B both implement the interface Immm. So you can say that an A object is a Immm object, and the same with any B objects you create.
Line 2 should be ok because the variable a refers to an object that is a Immm object. It is a widening conversion (your going from more specific to less specific) so no cast is needed.
Line 3 will compile because you are doing an explicit cast and the compiler will assume you know what your doing. However, when you get to the runtime it throws an exception because the object refered to by the variable iii is not a B object. It is an A object and a Immm object. But not a B object.
hope that helps
[ May 15, 2002: Message edited by: Dave Vick ]