What is the result?

Given the code fragment:

What is the result?
A. Execution terminates in the first catch statement, and caught a RuntimeException is printed to the console.
B. Execution terminates In the second catch statement, and caught an Exception is printed to the console.
C. A runtime error is thrown in the thread "main".
D. Execution completes normally, and Ready to use is printed to the console.
E. The code fails to compile because a throws keyword is required.

Download Printable PDF. VALID exam to help you PASS.

3 thoughts on “What is the result?

  1. C
    public static void main(String[] args) {
    // ArrayList myList = new ArrayList();
    ArrayList myList = new ArrayList();
    String myarray[];
    while(true){ //infinite loop so Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
    myList.add(“My string”);}
    }catch (RuntimeException re){
    System.out.println(“caught RuntimeException”);
    }catch (Exception e){
    System.out.println(“caught Exception”);
    System.out.println(“Ready to use”);

  2. I guess none of the available options are correct! The while loop is infinite so the program will keep running forever.

Leave a Reply

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

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