java.lang.StackOverflowError 曾经终败给现在 2021-09-24 11:12 369阅读 0赞 当子类与父类,循环调用会报次错 public class Father { protected void doSomething() { System.out.println("2"); //注意这里的this在调用的实时,实际上是son的实例 this.doSomething(); System.out.println(this.getClass().getSimpleName()); } public static void main(String[] args) { Father father = new Son(); father.doSomething(); } } class Son extends Father { @Override public void doSomething( ) { System.out.println("2" ); super.doSomething(); } } ![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2Nvcmxlb25lXzRldmVy_size_16_color_FFFFFF_t_70][] [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2Nvcmxlb25lXzRldmVy_size_16_color_FFFFFF_t_70]: /images/20210923/9873276415e642bdb37a83be6783c6df.png
还没有评论,来说两句吧...