Menu
Question Index
...

What will be the output of the following program?

class FinallyDemo {
    String name;
    int no1, no2;
    FinallyDemo(int args[]) throws Throwable {
        try {
            name = new String("College Name");
            no1 = Integer.parseInt("" + args[0]);
            no2 = Integer.parseInt("" + args[1]);
            finalize();
            System.out.println(name + "\n" + "Division result is " + no1 / no2);
        } catch (ArithmeticException ae) {
            System.out.println("Cannot divide by zero");
        } finally {
            name = null;
            System.out.println("Finally Executed");
        }
    }
    public static void main(String[] arg) throws Throwable {
        int agrs[] = {10, 5, 30, 60};
        new FinallyDemo(agrs);
    }
}


College Name
Division result is 0
Finally Executed
College Name
Division result is 2
College Name
Division result is 2
Finally Executed
Finally Executed
Compilation Error or Runtime Error

Doubts

Problems

Topic: Methods Of Integer, Long Classes In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App