What is the result?

Given the following code for the classes MyException and Test:

What is the result?
A. A
B. B
C. Either A or B
D. A B
E. A compile time error occurs at line n1

Download Printable PDF. VALID exam to help you PASS.

4 thoughts on “What is the result?

  1. Answer B:

    It will always print “B”, because the method1() method catches any RunTimeException, including the child exception class, MyException.

  2. Answer is B

    public class Test {
    public static void main(String[] args) {
    try {
    } catch (MyException e) {

    public static void method1(){
    try {
    throw Math.random() > 0.5 ? new MyException() : new RuntimeException();
    } catch (RuntimeException re) {

    class MyException extends RuntimeException{}

Leave a Reply

Your email address will not be published. Required fields are marked *

The reCAPTCHA verification period has expired. Please reload the page.