ProgrammingHardProduct-company placement · Java
How many of these statements about Java exceptions are correct? (i) An overriding method may throw any unchecked exception, even if the overridden method declares none. (ii) Catching a checked exception (other than Exception or Throwable) that the try block can never throw is a compile-time error. (iii) A finally block does not run when the try block executes a return statement. (iv) A try block may be followed by finally alone, without any catch.
- A. 2
- B. 3
- C. 4
- D. 1
Correct answer: B. 3
(i), (ii) and (iv) are true. (iii) is false: finally runs on return, break, continue and exceptions; only things like System.exit or a JVM crash skip it.
More OOP with C++ and Java questions
- What happens when this code is compiled? java try { new java.io.FileReader("x.txt"); } catch (java.io.IOException | Exception e) {…
- What is printed? java try { throw null; } catch (NullPointerException e) { System.out.print("NPE"); } catch (Exception e) {…
- What is printed? java int i = 0; while (true) { try { i++; if (i == 3) break; } finally { System.out.print(i); } }
- What is printed? java String s = null; switch (s) { case "a": System.out.print("A"); break; default: System.out.print("D"); }
- What is printed? java class Box<T> { static int count = 0; Box() { count++; } } // in main: new Box<String>(); new Box<Integer>(); new…
- Which lines fail to compile? java class G<T> { T[] arr = new T[10]; // L1 T make() { return new T(); } // L2 boolean is(Object o) { return…