父类: package com.roger.sub; public class Person { private String name; private int age; private Student s = new Student(); public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public void task() { s.study(); System.out.println("this is person"); } } 子类: package com.roger.sub; public class Student extends Person { private String school; public String getSchool() { return school; } public void setSchool(String school) { this.school = school; } public void study() { System.out.println("studying!"); } public static void main(String[] args) { Student s = new Student(); s.study(); } } 在父类中创建子类对象,导致无限循环,最终栈内存溢出。
死循环导致java.lang.StackOverflowError -- 栈内存溢出
最新推荐文章于 2023-02-15 21:36:34 发布