Java OCA OCP Practice Question 3204

Question

Consider the following class hierarchy from the package javax.security.auth.login and answer the questions.

LoginException/*from ww w .  ja v a  2s . com*/
    +
    |
   AccountException
       +
       |
      AccountExpiredException     
       +
       |  
      AccountLockedException     
       +
       |
      AccountNotFoundException

Which of the following handlers that makes use of multi-catch exception handler feature will compile without errors?

  • A. catch (AccountException | LoginException exception)
  • B. catch (AccountException | AccountExpiredException exception)
  • C. catch (AccountExpiredException | AccountNotFoundException exception)
  • D. catch (AccountExpiredException exception1 | AccountNotFoundException exception2)


C.

Note

For A and B, the base type handler is provided with the derived type handler, hence the multicatch is incorrect.

For D, the exception name exception1 is redundant and will result in a syntax error.

C is the correct option and this will compile fine without errors.




PreviousNext

Related