I know following cyclic inheritance hierarchy is not allowed in Java. Compiler throws an error, but what I'm really interested is knowing the exact reason for the compilation failure.
class A extends B{}
class B extends C{}
class C extends A{} // this will give you compile time error.
What is the thing due to which the compiler will throw an error, the moment I write the code class C extends A{}
Such relation is simply not possible. It defines an infinite recursive class. In order to define class C
, you need class A
, to define class A
you need class B
, and to define class B
you need class C
- and you are back to the starting point. This goes on infinitely so compiler can't do this and it also has no logical meaning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With