Menu
Question Index
...

Given the following hierarchy of exceptions what will be the output of the program?

class AEx extends Exception
{
}

class BEx extends Exception
{
}

class CEx extends Exception
{
}

class TestExceptions
{
    public static void main(String s[]) throws AEx, BEx, CEx
    {
        System.out.println("Before A");
        methodA(false);
        System.out.println("Before B");
        methodB(false);
        System.out.println("Before C");
        methodC(false);
    }

    public static void methodA(boolean value) throws AEx
    {
        if(value) throw new AEx();
    }

    public static void methodB(boolean value) throws AEx
    {
        if(value) throw new BEx();
    }

    public static void methodC(boolean value) throws CEx
    {
        if(value) throw new CEx();
    }
}


Before A
Before B
Before C
Before A
Compilation Error
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