10. public class ClassA {
11. public void count(int i) {
12. count(++i);
13. }
14. }
And:
20. ClassA a = new ClassA();
21. a.count(3);
Which exception or error should be thrown by the virtual machine?
A. StackOverflowError
B. NullPointerException
C. NumberFormatException
D. IllegalArgumentException
E. ExceptionlnlnitializerError
Answer: A如题~~高人帮我讲讲为什么然后说说A选项这个错误是什么意思??
11. public void count(int i) {
12. count(++i);
13. }
14. }
And:
20. ClassA a = new ClassA();
21. a.count(3);
Which exception or error should be thrown by the virtual machine?
A. StackOverflowError
B. NullPointerException
C. NumberFormatException
D. IllegalArgumentException
E. ExceptionlnlnitializerError
Answer: A如题~~高人帮我讲讲为什么然后说说A选项这个错误是什么意思??
count(++i);
无限递归,没有出口,当然要溢出
对CSDN无语
我以为第一次没提交上去
哦~~意思是要用个if(i<x)这种语句来限制一下i~~不能让他无限递增下去是吧
顺便忙帮讲讲A选项这个错误是什么意思呢??
递归必须有个递归出口
你那个函数根本没有出口
比如你可以判断i满足什么条件时就return就好了