Menu
Question Index
...

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();
    }
}


Before Abcd
Before Efgh
Before Ijkl
Before Abcd
Before Efgh
Efgh
Before Ijkl
Before Abcd
Abcd
Before Efgh
Efgh
Before Ijkl
Ijkl
Before Abcd
Abcd
Before Efgh
Efgh
Before Ijkl
Before Abcd
Before Efgh
Efgh
Before Ijkl
Ijkl
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Throw Keyword - Java Throws Keyword

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App