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 needclass A, to defineclass Ayou needclass B, and to defineclass Byou needclass 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.