ProgrammingHardAccenture · Cognizant GenC
A Java method has this structure. What happens when it is compiled?
A Java method has this structure. What happens when it is compiled?
try {
reader.read(); // throws IOException
} catch (Exception e) {
} catch (IOException e) {
}- A. It compiles and the second catch handles IOException
- B. It compiles; both catch blocks run for an IOException
- C. Compile error: IOException has already been caught
- D. It compiles but throws an error at run time
Correct answer: C. Compile error: IOException has already been caught
A subclass handler placed after its superclass handler is unreachable, which javac reports as an error.
More OOP with C++ and Java questions
- What is printed? (C++, assume <iostream> and using namespace std) cpp struct B { virtual void f() = 0; }; void B::f() { cout << "B"; }…
- What is printed? java String s = "a"; s.concat("b"); s += "c"; System.out.print(s);
- What is printed? (C++, assume <iostream> and using namespace std) cpp struct B { void f(int) { cout << "Bi"; } }; struct D : B { void…
- What is printed? java class A { static { System.out.print("S"); } { System.out.print("I"); } A() { System.out.print("C"); } } // in main…
- What is printed? (C++, assume <iostream> and using namespace std) cpp class B { public: void call() { f(); } private: virtual void f() {…
- What is printed? java static void f(long x) { System.out.print("long"); } static void f(Integer x) { System.out.print("Integer"); } static…