Computer Science · Java Programming
What will be the output of the following Java program? public class ExceptionTest { public static void main(String[] args) { try { System.out.println('Result: ' + calculate(10, 0)); } catch (ArithmeticException e) { System.out.println('ArithmeticException caught: ' + e.getMessage()); } catch (Exception e) { System.out.println('General exception caught: ' + e.getMessage()); } finally { System.out.println('In finally block.'); } } public static int calculate(int a, int b) throws Exception { try { return a / b; } catch (ArithmeticException e) { throw new Exception('Division by zero not allowed'); } finally { System.out.println('Inner finally block executed.'); } } }
- 1Inner finally block executed. General exception caught: Division by zero not allowed In finally block.✓
- 2Inner finally block executed. General exception caught: / by zero In finally block.
- 3Inner finally block executed. Result: 0 In finally block.
- 4Inner finally block executed. ArithmeticException caught: / by zero In finally block.
Correct answer
Inner finally block executed. General exception caught: Division by zero not allowed In finally block.
Download Single Question PDF
Save this question and verified answer as a clean study sheet with live clickable link.
Share with Friends & Study Groups
Challenge your peer aspirants on WhatsApp or Telegram to solve this question!
Preparing for Computer Science?
Practice full-length mock tests with real exam timers, instant score analysis, and all-India ranking.
Want more practice questions on Java Programming?
Solve complete topic-wise tests with detailed solutions on GkGet.
Related Practice Questions
Recommended practice questions in Computer Science · Java Programming