Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cyclic inheritance hierarchy in Java

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{}

like image 285
user85 Avatar asked Dec 01 '22 04:12

user85


1 Answers

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.

like image 125
SomeWittyUsername Avatar answered Jan 01 '23 04:01

SomeWittyUsername