Menu
Topics Index
...
`

Mixing Exceptions Test


If you need explanation Read this topic

If you need Answer Take test on this topic

Mixing Exceptions Test
What set of lines when placed at PLACE LINES HERE will allow the program to compile successfully? Note that the order of lines is also important. Choose the option where all sets are valid.
public class MixingExceptionsTest {
    //LINE A = catch (CanNotMixException e) {}
    //LINE B = catch (CanNotGrindException e) {}
    //LINE C = catch (CanNotPulseException e) {}
    //LINE D = catch (Exception e) {}
    //LINE E = catch (Throwable e) {}
    public static void main(String[] args) {
        try {
            Mixer m = new Mixer();
            m.mix();
            m.grind();
            m.pulse();
        }
        /* PLACE LINES HERE */
    }
}
class CanNotMixException extends Exception {}
class CanNotGrindException extends Throwable {}
class CanNotPulseException extends RuntimeException {}

class Mixer {
    void mix() throws CanNotGrindException {}
    void grind() throws CanNotMixException {}
    void pulse() throws CanNotPulseException {}
}

A. DE,E,BD,DB,A,B
B. DE,E,BD,ABC,BAC,CBA,AB,BA,
C. DE,ED,E,BD,DB,ABC,
D. DE,BD,DB,AB,BA,EA,
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.

B.is the answer.all the combination of these sets dont let to raise an external error so B is the answer.

Posted by Shabaaz Shaikz    2014-04-08 12:45:34


Ans is D.  The exceptions thrown by the methods mix(), grind() and pulse() are to be caught. as mix throws CanNotMixException which extends Exception, either the same exception can be caught or the super class ,i.e, Exception can be caught. Same with grind() and pulse() methods.

Posted by Nikhil Sulibhavi    2014-04-08 12:49:31


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

Posted by Merit Campus    2014-04-09 03:58:42


ThanQ:-)

Posted by Shabaaz Shaikz    2014-04-09 12:12:02


© meritcampus 2019

All Rights Reserved.

Open In App