ProgrammingHardWipro Elite · TCS NQT Prime

What is printed?

What is printed?
Object[] o = new String[1];
try { o[0] = 1; System.out.print("T"); }
catch (ArrayStoreException e) { System.out.print("S"); }
finally { System.out.print("F"); }
  1. A. TF
  2. B. F
  3. C. Compile error
  4. D. SF

Correct answer: D. SF

Arrays are covariant but check the store at run time; an Integer into a String[] throws ArrayStoreException, then finally runs.

More OOP with C++ and Java questions

Exams that ask this topic