膀胱冲洗 ppt:java中的一个小问题
来源:百度文库 编辑:中科新闻网 时间:2024/05/16 01:58:38
class Test{
Test test=new Test();
public void f1(){
System.out.println("f1()");
}
public void f2(){
System.out.println("f2()");
}
}
public class TestExtends extends Test{
public static void main(String[] args){
TestExtends a1=new TestExtends();
a1.f1();
}
}
出现Exception in thread "main" java.lang.StackOverflowError
Why
Test test=new Test();
public void f1(){
System.out.println("f1()");
}
public void f2(){
System.out.println("f2()");
}
}
public class TestExtends extends Test{
public static void main(String[] args){
TestExtends a1=new TestExtends();
a1.f1();
}
}
出现Exception in thread "main" java.lang.StackOverflowError
Why
栈溢出错误
字段Test test=new Test(); 中导致死循环,Test类不能实例化。