Topics Index

Finally and throws keyword

If you need explanation Read this topic

If you need Answer Take test on this topic

Finally and throws keyword
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]);
            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);

A. College Name
Division result is 0
Finally Executed
B. College Name
Division result is 2
C. College Name
Division result is 2
Finally Executed
D. Finally Executed
E. Compilation Error or Runtime Error
Topic: Methods Of Integer, Long Classes In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans is no exception is generted catch doesnt execute and finally no1=10,no2=5 division is 2

Posted by Santosh Munugota    2013-07-08 12:56:34

C it is ! in main method d constructor is called enters the try block,takes the string , then args[0] will have 10 args[1] have 5 which are no1 and no2 actually. thus Division result will be 2,as there is no exception occured it goes to finally block and excutes that statment as well ! Thus C will b the answer !

Posted by Shaik Nyamath    2013-07-08 12:58:12

Congratulations Santosh Munugota. You are this dose winner. Please send us your mobile details and we will process the recharge asap.

Posted by Merit Campus    2013-07-09 00:55:13

got rc :)

Posted by Santosh Munugota    2013-07-21 15:21:01

© meritcampus 2019

All Rights Reserved.

Open In App