What is the max level of inheritance in java?

前端 未结 5 1302
北海茫月
北海茫月 2020-12-20 17:15

I was wondering if there is a finite number of time that I can inherit a class? Or what are the factors that can influence this?

相关标签:
5条回答
  • 2020-12-20 17:42

    For all practical applications, inheritance trees in Java may grow to infinite size.

    0 讨论(0)
  • 2020-12-20 17:44

    There's no specific limit in the specification.

    There's probably a implementation-dependent limit, if only in that you're limited by the available memory (class information needs to be stored somewhere after all).

    And if you ever reach that limit, your design is broken anyway (anything that goes into the double digits is definitely a code smell).

    0 讨论(0)
  • 2020-12-20 17:46

    Read this (Its fun)

    The system is out of resources.
    Consult the following stack trace for details.
    java.lang.StackOverflowError
    
    0 讨论(0)
  • 2020-12-20 17:50

    If a class is final, you cannot inherit it.

    Besides that, you can have infinitely inheritance trees. You can also infinitely implement many interface classes too.

    0 讨论(0)
  • 2020-12-20 17:54

    There is no limit specified. For all practical purposes, it is infinite.

    0 讨论(0)
提交回复
热议问题