Menu
Question Index
...

What will be the output of the following program?

public class Comparison {
    public static void main(String args[]) {
        int i = 1;
        int j = 1;
        int k = 2;
        try {
            i++;
            j--;
            k--;
            if ((k / j > k / i)) {
                i++;
            }
        } catch (ArithmeticException e) {
            System.out.println("arithmetic error.");
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("index out of bounds error.");
        } finally {
            System.out.print("final block execute.");
        }
    }
}


arithmetic error.
final block execute.
index out of bounds error.
final block execute.
arithmetic error.
index out of bounds error.
final block execute.
final block execute.
Compilation Error or Runtime Error for some other reason

Doubts

Problems

Topic: Java Built In Exceptions Checked Exceptions, Unchecked Exceptions

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App