Up-casting is often useful, and down-casting is allowed by the
compiler, but can be dangerous at run time.
Now, what is casting? You cast an object when you want to treat
it as a different type - very helpful at times. For example, consider
javaBook, an object of type JavaBook (JavaBook extends Book).
If my interest is the numberOfPages in javaBook, it can be up-casted
to class Book with confidence.
Book temp1 = (Book)javaBook; // up-cast is quite safe
int pageCount = temp1.getPages();[/code]
Starting with a simple Book object, myBook, however, and looking for
its chapter on JVM doesn't work so well because it doesn't have one.
JavaBook temp2 = (JavaBook)myBook; // down-cast is allowed but
int jvmChapter = temp2.getJvmChapter(); // run-time error on cast
Jim...