Multiple choice technology programming languages

Line 1. public class ClassA { Line 2. public void count(int i) { Line 3. count(++i); Line 4. } Line 5. } And: Line 6. ClassA a = new ClassA(); Line 7. a.count(3); Which exception or error should be thrown by the virtual machine? A. StackOverflowError B. NullPointerException C. NumberFormatException D. IllegalArgumentException E. ExceptionlnlnitializerError

  1. A

  2. B

  3. C

  4. D

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The method count recursively calls itself with ++i without any base case or termination condition, leading to infinite recursion. This rapidly exhausts the execution stack and throws a java.lang.StackOverflowError.

AI explanation

The method count(int i) calls itself with count(++i) and has no base case or terminating condition, so it recurses indefinitely. Each recursive call consumes another frame on the call stack, and since there's nothing to stop the recursion, the stack eventually runs out of space, causing the JVM to throw a StackOverflowError rather than any of the other listed exceptions.