As described in the Kathy & Bert book on pg 234, will the following throw a class cast exception or generate a compiler error?
int  books = new int ;
int  numbers = new int;
books=aNumber; //no since it expects an int array not int
Confusion comes into play from Chapter 3 Test question 3.
P.S. I am sure it is an exception but as if it was C/C++, this would definitely generate a compiler error, how come Java does not follow suit?
The compiler trusts you while doing an explicit cast from o1 (which is actually a type of Object) to an int.
This might work for the compiler cause you do it explicitly. The compiler does not know what type of object o1 is realy referencing. So he accepts, that you know.
Since "o1" is refferencing an int (2-D int array) you'll get a ClassCastException at runtime. This is by the fact you did not know what you're doing and the compiler trusted you.
Would you have made "o1" refferencing to "b", which is actually an int array, this might work.
Youst keep in mind: The compiler does not know what o1 will be refferencing at runtime. The only thing he knows, that you have an int array "b2" and and you want to have b2 somewhen refferencing o1. You say o1 will be an int array that time. The compiler believes you and gets disappointed at runtime.
Power from within.
Failed SCJP 2 times :-(
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com