Menu
Question Index
...

If expections AEx and BEx are defined as shown below, which of the methods in the ExceptionsTest class fail to compile?

class AEx extends Exception {}
class BEx extends AEx {}

class ExceptionsTest {

    void m1() {
        try { throwA(false); throwB(true); } catch (BEx aex) { }
    }
    void m2() {
        try { throwA(true); throwB(false); } catch (AEx bex) { }
    }
    void m3() throws AEx {
        try {
            throwA(false); throwB(true);
        } catch (BEx bex) {
            throw bex;
        }
    }
    void m4() throws BEx {
        try {
            throwA(true); throwB(false);
        } catch (AEx aex) {
            throw aex;
        }
    }

    void throwA(boolean throwEx) throws AEx {
        if (throwEx) throw new AEx();
    }
    void throwB(boolean throwEx) throws BEx {
        if (throwEx) throw new BEx();
    }
}


m1, m2, m3, m4
m1, m2, m3
m3, m4
m1, m4
m2, m3

Doubts

Problems

Topic: Exception Handling Syntax In Java Programming

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App