exam questions

Exam 1z0-808 All Questions

View all questions & answers for the 1z0-808 exam

Exam 1z0-808 topic 1 question 45 discussion

Actual exam question from Oracle's 1z0-808
Question #: 45
Topic #: 1
[All 1z0-808 Questions]

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.
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
letmein2
Highly Voted 5 years, 6 months ago
Correct. I guess there would be a java.lang.OutOfMemoryError.
upvoted 13 times
...
v323rs
Highly Voted 4 years, 11 months ago
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
upvoted 9 times
...
vic88
Most Recent 2 weeks ago
Selected Answer: C
correct answer is C
upvoted 1 times
...
Vicky_65
1 year, 8 months ago
Selected Answer: C
it prints infinitely.
upvoted 1 times
...
odzio33
1 year, 11 months ago
Selected Answer: C
import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList myList = new ArrayList(); String[] myArray; try{ while (true){ myList.add("My string"); } }catch (RuntimeException e){ System.out.println("catch RunTimeException"); }catch (Exception e){ System.out.println("catch Exception"); } System.out.println("Ready to use "); } } 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:265) at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:239) at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:231) at java.util.ArrayList.add(ArrayList.java:462) at catch_error_loop_true.Main.main(Main.java:11)
upvoted 1 times
...
akbiyik
2 years ago
java.lang.OutOfMemoryError
upvoted 1 times
...
UAK94
2 years, 2 months ago
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space Answer is C. P.S. In code fragments you have to assume that required imports are done!!!
upvoted 2 times
...
Mthlagi
2 years, 10 months ago
The correct answer is C.
upvoted 1 times
...
aabbcc99
3 years, 2 months ago
None of the answers are correct, there is no import for Arraylist so compilation fails
upvoted 3 times
tawa_z58
1 year, 10 months ago
these are code snippets so assume all imports are done and focus on the given problem code fragments
upvoted 1 times
...
rebelsta
2 years, 7 months ago
very smart. You'll surely crack OCA.
upvoted 7 times
...
...
claudevan
3 years, 2 months ago
A JVM executa o codigo até um certo porto do loop "while(true)" na minha máquina eu conseguir simular 56 entradas no ArrayList, ao verificar o consumo de memoria excessivo a JVM para a execução para evitar um erro de java.lang.OutOfMemoryError, dessa forma o código acima executa sem erro na JVM. Porém existe um "Erro de tempo de execução" que a JVM omite. A resposta correta é a questão C onde diz que existe um "Erro de tempo de execução!".
upvoted 1 times
...
Tarik2190
3 years, 10 months ago
Answer is C: public static void main(String[] args) { ArrayList myList = new ArrayList(); String[] myArray; try{ while (true) { } } catch (RuntimeException e) { System.out.println("Caught a RuntimeException"); } catch (Exception e) { System.out.println("Caught an Exception"); } System.out.println("Ready to use"); }
upvoted 1 times
...
Ayla
4 years, 1 month ago
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
upvoted 2 times
...
365everyday
4 years, 2 months ago
The while loop executes continuously, and keeps shoving strings into the array. Eventually the program will fail, because it will run out of memory (hence the error). Nothing gets printed, as there are no exceptions thrown and the println statement is never reached.
upvoted 7 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago