A student places the following Java statements inside a main method, with no exception handling, then compiles and runs the program:


Java
int[] scores = new int[5];
scores[5] = 90;
System.out.println("Saved");


Which statement correctly describes what happens?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A Java shipping program stops and prints this stack trace, a diagnostic report showing the exception and the method calls active when it occurred. Match each report component to its meaning in this example.


Java
Exception in thread "main" java.lang.ArithmeticException: / by zero
    at Shipping.average(Shipping.java:18)
    at Shipping.main(Shipping.java:7)
Match each term
A.

Shipping.average was executing line 18 when the failure occurred.

B.

/ by zero describes the arithmetic operation that failed.

C.

ArithmeticException identifies the class of runtime failure.

D.

Shipping.main invoked the calculation from line 7.

Caller frame

Detail message

Throw-site frame

Exception type

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Each numbered Java statement group below runs on its own inside a fresh main method with no exception handling. For each one, type the simple class name of the runtime exception it throws, such as ArithmeticException, or type none if it runs without throwing an exception.

  1. int x = Integer.parseInt("12.5");
  2. String name = null; int n = name.length();
  3. int d = 0; int q = 7 / d;
  4. double r = 7.0 / 0;
  5. String w = "code"; char c = w.charAt(4);
  6. Object o = "hi"; Integer k = (Integer) o;
StatementException thrown
Statement 1
Statement 2
Statement 3
Statement 4
Statement 5
Statement 6

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors