Given the code fragment:
How many lines of text does this program print?
Given the code fragment:
How many lines of text does this program print?
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'.
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.
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
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!" ); }}
Exeception 1 Finally Block