ProgrammingHardProduct-company placement · Java
What is printed?
What is printed?
try {
System.out.print("T");
System.exit(0);
} finally {
System.out.print("F");
}- A. T
- B. TF
- C. FT
- D. F
Correct answer: A. T
System.exit stops the JVM; the try block never completes, so the finally block is not run. (finally covers return, break and exceptions, not JVM termination.)
More OOP with C++ and Java questions
- What is printed? java class N { public Object clone() throws CloneNotSupportedException { return super.clone(); } } // in main: try { new…
- What is printed? java System.out.print((List.of(1, 2).hashCode() == List.of(2, 1).hashCode()) + " " + (Set.of(1, 2).hashCode() ==…
- What is printed? java // static methods of the main class: static void f(Object o) { System.out.print("O"); } static void f(Object[] a) {…
- What is printed? java class Range implements Iterable<Integer> { public Iterator<Integer> iterator() { return List.of(1, 2, 3).iterator()…
- Which line fails to compile (C++17)? cpp struct A { A() = default; A(const A&) = delete; A(A&&) = default; }; A make() { A a; return a; }…
- What is printed? cpp int main() { const string s = "x"; string t = std::move(s); cout << s << t; }