nerdexam
Oracle

1Z0-803 · Question #238

Given: class MarksOutOfBoundsException extends IndexOutOfBoundsException { } public class GradingProcess { void verify(int marks) throws IndexOutOfBoundsException { if (marks > 100) { throw new MarksO

The correct answer is C. Class MarketOutOfBoundsException. The value 104 will cause aMarketOutOfBoundsException

Handling Exceptions

Question

Given:

class MarksOutOfBoundsException extends IndexOutOfBoundsException { } public class GradingProcess { void verify(int marks) throws IndexOutOfBoundsException { if (marks > 100) { throw new MarksOutOfBoundsException(); } if (marks > 50) { System.out.print("Pass"); } else { System.out.print("Fail"); } } public static void main(String[] args) { int marks = Integer.parseInt(args[2]); try { new GradingProcess().verify(marks)); } catch(Exception e) { System.out.print(e.getClass()); } } } And the command line invocation:

Java grading process 89 50 104 What is the result?

Options

  • APass
  • BFail
  • CClass MarketOutOfBoundsException
  • DClass IndexOutOfBoundsException
  • EClass Exception

How the community answered

(42 responses)
  • A
    5% (2)
  • B
    12% (5)
  • C
    57% (24)
  • D
    21% (9)
  • E
    5% (2)

Explanation

The value 104 will cause aMarketOutOfBoundsException

Topics

#custom exceptions#exception hierarchy#try-catch#command-line arguments#Integer.parseInt()

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice