1z0-819 Exam QuestionsBrowse all questions from this exam

1z0-819 Exam - Question 123


Given the code fragment:

How many lines of text does this program print?

Show Answer
Correct Answer: D

The program prints two lines of text. The if condition in the try block evaluates to true since 'oracle'.equals('ORACLE'.toLowerCase()) is true. This causes a NoMatchException to be thrown. The first catch block catches this exception and prints 'Exception 1'. Regardless of whether an exception is thrown or not, the finally block always executes, printing 'Finally Block'. Therefore, the output consists of two lines: 'Exception 1' and 'Finally Block'.

Discussion

4 comments
Sign in to comment
StavokOption: D
Jul 20, 2023

The code provided is missing the definition of the NoMatchException class. If we assume that NoMatchException is a custom exception class that extends Exception or RuntimeException, then the code will compile and run without any issues. The first catch block will catch this exception and print "Exception 1" to the console. After that, the finally block will be executed, printing "Finally Block" to the console.

JticOption: D
Feb 23, 2023

Exeception 1 Finally Block

OmnisumemOption: D
Oct 3, 2023

Tested: D. Example of NoMatchException as custom exception class could be: class NoMatchException extends Exception { public static void main(String args[]) { System.out.println("No Match Exception Caught!" ); }}

ASPushkinOption: D
May 16, 2024

lets say NoMatchExcepton extends Exception pay attention to two things : multi-catch exceptions can not be subclassed order of catch blocks subclass before superclass Evrth is ok with that So just two lines are printed