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

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. 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


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

© meritcampus 2019

All Rights Reserved.

Open In App