Which of these outputs is valid? try { int a = 10; int b = 0; int c = a / b; Sys
ID: 3840095 • Letter: W
Question
Which of these outputs is valid?
try {
int a = 10;
int b = 0;
int c = a / b;
System.out.printf("c = %d ", c);
}
catch (ArithmeticException ex) {
System.out.println("ArithmeticException caught!");
}
catch (Throwable ex) {
System.out.println("Some exception caught!");
}
finally {
System.out.println("Division operation is completed");
}
c = 0
ArithmeticException caught!
Division operation is completed
ArithmeticException caught!
Division operation is completed
Division operation is completed
ArithmeticException caught!
Some exception caught!
Division operation is completed
ArithmeticException caught!
Some exception caught!
Division operation is completed
c = 0
ArithmeticException caught!
Division operation is completed
ArithmeticException caught!
Division operation is completed
Division operation is completed
ArithmeticException caught!
Some exception caught!
Division operation is completed
ArithmeticException caught!
Some exception caught!
Division operation is completed
Explanation / Answer
line : int c = a / b; will throw ArithmeticException exception
So, first catch block will execute and after that finally block will execute
So, output:
ArithmeticException caught!
Division operation is completed
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.