Home Subjects Java Programming Exception Handling

Java Programming
Exception Handling

Java OOP, collections, multithreading

51 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 51–51 of 51
Topics in Java Programming
Q.51 Medium Exception Handling
What is the output of the following code?
int x = 10;
try {
x = x / 0;
} catch(ArithmeticException e) {
x = x + 5;
} finally {
x = x * 2;
}
System.out.println(x);
A 10
B 30
C 20
D 40
Correct Answer:  B. 30
EXPLANATION

ArithmeticException is caught, x becomes 10+5=15. Finally block executes, x becomes 15*2=30. Finally block always executes regardless of exception.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips