Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 85

Given:

class UserException extends Exception { }

class AgeOutOfLimitException extends UserException { }

and the code fragment:

class App {

public void doRegister(String name, int age)

throws UserException, AgeOutOfLimitException {

if (name.length () < 6) {

throw new UserException ();

} else if (age >= 60) {

throw new AgeOutOfLimitException ();

} else {

System.out.println("User is registered.");

}

}

public static void main(String[ ] args) throws UserException {

App t = new App ();

t.doRegister("Mathew", 60);

}

}

What is the result?

    Correct Answer: B

    The code fragment shows that if the age is greater than or equal to 60, an AgeOutOfLimitException is thrown. Since the age provided in the main method is 60, the condition is met and thus an AgeOutOfLimitException is thrown.

Discussion
Elena_CorinaOption: B

B tested. Exception in thread "main" AgeOutOfLimitException

asdfjhfgjuaDCVOption: B

B is the correct answer

steefaandOption: B

Answer is B. It is ok that main doesn't declare AgeOutOfLimit since it declares its parent class.

mevltOption: B

Child exception is not necessary to be declared in method definition. But it is defined, it won't hurt