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.
C.
A runtime error is thrown in the thread “main”.
Definitely C.
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3210)
at java.util.Arrays.copyOf(Arrays.java:3181)
at java.util.ArrayList.grow(ArrayList.java:261)
at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:235)
at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:227)
at java.util.ArrayList.add(ArrayList.java:458)
at Test03.main(Test03.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
yes answer is C, reason is While loop executes infinitely and we will get Exception in thread “main” java.lang.OutOfMemoryError: Java Heap Space
Answer: C
output:
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
c