增加对象的实例变量是否会导致堆栈溢出错误?
例如:
此方法(java)将导致堆栈溢出错误:
class StackOverflow {
public static void StackOverflow (int x)
{
System.out.println (x) ;
StackOverflow(x+1) ;
}
public static void main (String[]arg) { StackOverflow (0) ;
}
Run Code Online (Sandbox Code Playgroud)
但这会是吗?:( .....是我为缩短代码而设置的差距.它足够长.)
import java.util.*;
class Dice
{
String name ;
int x ;
int[] sum ;
Run Code Online (Sandbox Code Playgroud)
....
public Dice (String name)
{
this.name = name ;
this.x = 0 ;
this.sum = new int[7] ;
}
Run Code Online (Sandbox Code Playgroud)
....
public static void main (String[] arg)
{
Dice a1 = new Dice ("a1") ; …Run Code Online (Sandbox Code Playgroud)