I thought that I would add an as-of-yet unstated Java specific answer to this thread. In Java, every class must ultimately be derived from the Object
class. That's why every object can be casted to an instance of Object
without issue. To support this fact, the Java Inheritance Tutorial states:
Excepting Object, which has no superclass, every class has one and only one direct superclass (single inheritance). In the absence of any other explicit superclass, every class is implicitly a subclass of Object.
Classes can be derived from classes that are derived from classes that are derived from classes, and so on, and ultimately derived from the topmost class, Object. Such a class is said to be descended from all the classes in the inheritance chain stretching back to Object.
If cyclic inheritance dependencies are allowed, and because classes in Java must have exactly one direct superclass (see above), then instances of classes in any cyclic dependency chain (e.g. instances of your classes A
, B
, and C
) could not be inherited from Object
, which is not permitted. So none of these cyclic dependency objects could be treated as Object
s. Thus, the compiler must forbid cyclic dependencies.