Java : Class inheriting self

后端 未结 8 1814
悲&欢浪女
悲&欢浪女 2021-02-15 11:21

I know this is pointless: I just find it funny and I want to inquire more about the mechanics of what happens when you create a class that inherits itself, resulting in a stack

8条回答
  •  情歌与酒
    2021-02-15 11:40

    When I try to compile :

    class A extends A {
    }
    

    I get :

    $ javac A.java
    A.java:1: cyclic inheritance involving A
    class A extends A {
    ^
    1 error
    

    So Java don't let you do this kind of thing. For information, java version "1.6.0_24"

提交回复
热议问题