猿问

JAVA 堆栈溢出

  • import java.awt.Button;
    
    
    public class A {
        private Button b ;
        
        public Button getB() {
            return b;
        }
    
        public void setB(Button b) {
            this.b = b;
        }
        
        A(){
            b = new Button();
            B b = new B(this);
        }
        public static void main(String[] args){
            new A();
        }
    }
    class B {
        A past = new A();
        B(A p){
            this.past = p;
        }
    }

     不太明白 为什么这段代码会报堆栈溢出的错误,,,


皈依舞
浏览 520回答 1
1回答

梦里花落0921

new A() 时需要newB() new B()时需要newA() 死循环了
随时随地看视频慕课网APP

相关分类

Java
我要回答