Question
Given this code in a method:
4. Integer[][] la = {{1,2}, {3,4,5}};
5. Number[] na = la[1];
6. Number[] na2 = (Number[])la[0];
7. Object o = na2;
8. la[1] = (Number[])o;
9. la[0] = (Integer[])o;
What is the result? (Choose all that apply.)
- A. Compilation succeeds.
- B. Compilation fails due to an error on line 4.
- C. Compilation fails due to an error on line 5.
- D. Compilation fails due to an error on line 6.
- E. Compilation fails due to an error on line 7.
- F. Compilation fails due to an error on line 8.
- G. Compilation fails due to an error on line 9.
- H. Compilation succeeds but an exception is thrown at runtime.
F is correct.
Note
Integer extends Number, so you can't refer an Integer[] reference to a Number[] (an Integer can do things a Number can't.).
PreviousNextRelated