开发者

What is the max level of inheritance in java?

开发者 https://www.devze.com 2023-01-20 06:07 出处:网络
开发者_JAVA技巧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?Read this (Its fun)
开发者_JAVA技巧

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?


Read this (Its fun)

The system is out of resources.
Consult the following stack trace for details.
java.lang.StackOverflowError


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


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).


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消