Download Printable PDF. VALID exam to help you PASS.
One thought on “What is the result?”
Option D.
public class Test {
public static void main(String[] args) {
Test t = new Test();
try {
t.doPrint();
t.doList();
} catch (Exception e2) {
System.out.println(“Caught ” + e2);
}
}
public void doList() throws Exception {
throw new Error(“Error”);
}
public void doPrint() throws Exception {
throw new RuntimeException(“Exception”);
}
}
Note:
The IDE doesnt understand “import java.io.Error” the closest working import would be “java.io.IOError” though this doesnt seem to influence the Output above?
Option D.
public class Test {
public static void main(String[] args) {
Test t = new Test();
try {
t.doPrint();
t.doList();
} catch (Exception e2) {
System.out.println(“Caught ” + e2);
}
}
public void doList() throws Exception {
throw new Error(“Error”);
}
public void doPrint() throws Exception {
throw new RuntimeException(“Exception”);
}
}
Output:
Caught java.lang.RuntimeException: Exception
Note:
The IDE doesnt understand “import java.io.Error” the closest working import would be “java.io.IOError” though this doesnt seem to influence the Output above?
Correct Answer is D