Menu
Topics Index
...
`

Try & Catch Block2846


If you need explanation Read this topic

If you need Answer Take test on this topic

Try & Catch Block2846
What will be the output of the following program?
class Abcd extends Exception {    }
class Efgh extends Exception {    }
class Ijlk extends Exception {    }
class Kids {
    public static void main(String s[]) throws Abcd, Efgh, Ijlk {
        System.out.println("Before Abcd");
        methodA(true);
        System.out.println("Before Efgh");
        methodB(false);
        System.out.println("Before Ijkl");
        methodC(true);
    }
    public static void methodA(boolean value) throws Abcd {
        try {
            if (value)    throw new Abcd();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
    public static void methodA(boolean value) throws Abcd {
        try {
            if (value)    throw new Abcd();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
    public static void methodB(boolean value) throws Efgh {
        try {
            if (!value)    throw new Efgh();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
    public static void methodC(boolean value) throws Ijlk {
        if (!value) throw new Ijlk();
    }
}

A. Before Abcd
Before Efgh
Before Ijkl
B. Before Abcd
Before Efgh
Efgh
Before Ijkl
C. Before Abcd
Abcd
Before Efgh
Efgh
Before Ijkl
Ijkl
D. Before Abcd
Abcd
Before Efgh
Efgh
Before Ijkl
E. Before Abcd
Before Efgh
Efgh
Before Ijkl
Ijkl
F. Compilation Error or Runtime Error
Topic: Java Throw Keyword - Java Throws Keyword

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.

f.
compilation err.
methodA defined 2 times

Posted by Maheshwari Natarajan    2014-08-07 12:41:33


Ans is F.
it gives compilation error because methodA is defined 2 times with the same signature.

Posted by Gopinath Manchikanti    2014-08-07 12:54:22


answer D
1st sop pritd
methdA() excptin detctd abcd ptintd.
2nd sop printd
method B() exception catchd n efhh printd
3 rd sop printd
method C() excutd.

Posted by NagaRaj Nataraj    2014-08-07 14:19:06


Congratulations Maheshwari Natarajan. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-08-08 04:31:07


© meritcampus 2019

All Rights Reserved.

Open In App