Given the following object hierarchy and code for the upgrade method:
java.lang.Object
|
+---- mypkg.BaseWidget
|
+---- TypeAWidget
// the following is a method in BaseWidget
1. public TypeAWidget upgrade( ){
2. TypeAWidget A = (TypeAWidget) this ;
3. return A ;
4. }
What will be the result of trying to compile and run a program containing the following statements?
5. BaseWidget B = new BaseWidget() ;
6. TypeAWidget A = B.upgrade() ;
A. The compiler will object to line 2.
B. A runtime ClassCastException will be generated in line 2.
C. After line 6 executes, the object referred to as A will in fact be a TypeAWidget.
Why is the answer B?
Explain me more clear .