Java OCA OCP Practice Question 621

Question

Fill in the blanks:

A ___ occurs when a program recurses too deeply into an infinite loop,

while a(n) ___ occurs when a reference to a nonexistent object is acted upon.

  • A. NoClassDefFoundError, StackOverflowError
  • B. StackOverflowError, NullPointerException
  • C. ClassCastException, IllegalArgumentException
  • D. StackOverflowError, IllegalArgumentException


B.

Note

A StackOverflowError occurs when a program recurses too deeply into an infinite loop.

It is considered an error because the JVM often runs out of memory and cannot recover.

A NullPointerException occurs when an instance method or variable on a null reference is used.

For these reasons, Option B is correct.

A NoClassDefFoundError occurs when code available at compile time is not available at runtime.

A ClassCastException occurs when an object is cast to an incompatible reference type.

An IllegalArgumentException occurs when invalid parameters are sent to a method.




PreviousNext

Related