Question No
of 25
1 Marks
+
What will be the output?
class inter {
public static void main(String args[]) {
int numi, num2;
try {
num1 =
0;
num2 62 / num1;
System.out.println("Try block message");
System.exit(0);
} catch (ArithmeticException e) {
System.out.println("Error: Don't divide a number by zero");
System.exit(0);
} finally {
System.out.println("Give another number of num1");
}
}
}
Answers
Answered by
0
Answer:
Error: Don't divide a number by zero
Explanation:
num1 is 0
when 62 / num1 is evaluated it throws ArithmeticException.
So the print statement and System.exit(0); is skipped.
Control goes to the catch block.
Error message is printed.
System.exit(0) is encountered program terminates.
Finally block doesn't get executed.
Similar questions