Oracle Certified Associate Java Se 8 Programmer · Free Practice Question Hard
Question 1
Consider the code:
- public class Test
- {
- public static void m1()
- {
- System.out.print("A");
- try
- {
- System.out.print("B");
- System.out.print(10/0);
- }
- catch (ArithmeticException e)
- {
- System.out.print("C");
- }
- finally
- {
- System.out.print("D");
- }
- System.out.print("E");
- }
- public static void main(String[] args)
- {
- m1();
- System.out.print("F");
- }
- }
What is the result?
-
A
ABCF
-
B
Compilation Fails.
-
C
ArithmeticException is thrown at runtime.
-
D
ABCDEF
Reveal correct answer
Correct answer: D
Explanation
Inside try block ArithmeticException raised and handled. Hence every print statement will be executed. Hence the output is: ABCDEFDiscussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
You must be logged in to post a comment.
