QuestionQ73

Exception Handling

Given:

Question Image

and this code fragment:

Question Image

Which statement is correct?

  • A The program throws ClassCastException.
  • B The program fails to compile.
  • C The program throws StockException.
  • D The program throws OutofStockException.
Explanation

OutofStockException is a checked exception, but it is declared in the throws clauses of both m and main. The StockException thrown in the try block is caught as an Exception; the catch block then creates and throws an OutofStockException, which propagates out of main.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!