You have C IS-A B IS-A A, so it is legal to cast from a C instance to a B instance. You need the cast of course because you're casting down (since the compiler only knows it is an A) from A to B instead of up.
The line you describe
a) Declares a variable named o2 and specifies it holds something that is AT-LEAST a B. It might be something more specific (like a C) but will not be something less specific (like an A) or something random (like a
String).
b) Converts the value in o1 to a B and stores the value in o2. A little explanation here: o1 IS-A C, but is stored in an A. The compiler knows that o1 is AT-LEAST an A, but could be something more specific like a B or a C (which it in fact is). You can't treat it like a C though because the compiler only knows you said it was an A.
o2 will call the method from the instance which it actually is. o2 IS-A C, because the object it was created from IS-A C. If you call m1() on both objects, you will find that they both refer to the C's implementation of the method. But the tricky part is if you ask for i on each object, you will find it refers to the object type it was declared as - o1 returns A's i and o2 returns B's i. This is because
Java handles variable
polymorphism differently than methods. Methods override and extend the functionality so you can call a method on a base class and it will execute the subclass's implementation. Variables will always return the instance they are located in. You cannot override a variable - redeclaring it in a subclass gives you two copies of the variable. When you reference the object as its subclass, you get the subclass variable, when you reference as the superclass, you get the superclass variable. This is called hiding.
Try compiling and running your example code then play with it a little - make sure that you call m1() from both instances, and read i from both instances to see what I mean.
The casting you need to be concerned with on the exam is object casting, and from what I remember of the beta the questions are similar to what you posted. You need to be able to determine if the code will compile, and if it compiles what the output will be. I found the OCJA to be pretty fair though. You need to know your stuff, but once you know it, they don't really go out of their way to trick you.