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"); }- A. TF
- B. F
- C. Compile error
- 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
- What is printed? java int i = 1; i = i++ + ++i; int j = 5; j += j++ 2; System.out.print(i + " " + j);
- What is printed? java short s = 1; s = (short) (s + 1); char c = 'A'; c += 1; c++; System.out.print(s + " " + c + " " + (c + 1));
- What is printed? java int i = 0; System.out.print(true ? 'a' : 0); System.out.print(true ? 'a' : i);
- What is printed? java class T { static int v = f(); static int f() { throw new RuntimeException(); } } // main: for (int k = 0; k < 2…
- What is printed? java outer: for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (j == 1) continue outer; if (i == 2) break…
- What is printed? java class A { static final int X = 5; static final Integer Y = 6; static { System.out.print("A"); } } // main…