Menu
Topics Index
...
`

Try & Catch Block


If you need explanation Read this topic

If you need Answer Take test on this topic

Try & Catch Block
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 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.

D is the answer

Posted by Asad Ahmed    2014-10-29 12:12:18


ANS is D as the Abcd ,Efgh,Ijlk are extended by Exception here exceptions are thrown by exception class

Posted by Ramya Reddy Addulla    2014-10-29 12:29:36


D

Posted by Ananthoju Arun Chary    2014-10-29 15:45:21


.Ans is D...here we have 3 user defined exceptions named with abcd,efgh,ijkl..these all classes are extending Exception class all these are became Checked exceptions..

in main class we have three methods..methodoA() it throwing Abcd exception
methodB() throwing Efgh exception
methodC() thrwoing Ijkl Exception...

throws--> is key word in java which is ued to indicate the system that Exceptions raied in this method defination wil not handled here..the caller of the method should handle this

so that in main method we are saying to JVM to handle by using throws keyword...
here we are calling three methods by passing boolean values...evry tim there exception wil b thrown and Correspong catch blcok wil get executed

Posted by Uday Kumar    2014-10-29 17:00:54


d

Posted by Shubham Bansal    2014-10-29 17:09:54


This dose is now closed and the winners are Ramya Reddy Addulla,  for 'First Correct Comment', Uday Kumar,  for 'Best Comment' and Šâí Râm for the 'Popular Comment'. The 'lucky liker' is Ramya Reddy Addulla. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-10-31 06:05:39


© meritcampus 2019

All Rights Reserved.

Open In App