File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes ClassCircularityError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "ClassCircularityError" Watch "ClassCircularityError" New topic


Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
According to JLS,
If circularly declared classes are detected at run time, as classes are loaded
(�12.2), then a ClassCircularityError is thrown.
But when I try this program, I get a compiler Error :cyclic inheritance involving A.

class A extends C
int x,u;
class C extends B
int a,b;
class B extends A
int g,h;
public class circulartest
public static void main(String[] args) {
A a=new A();

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

Note what it says: "If circularly declared classes are detected at runtime...".

In your case, it is detected at compile time, so you get a compiler error.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
The compiler is pretty "smart" and I have never seen a case where someone has successfully created a circular reference where it got past the compiler and made it to run-time. The way the compiler handles your classes makes it very easy for it to catch this type of problem before it ever runs.

~Currently preparing for SCJP6
I agree. Here's the link:
subject: ClassCircularityError
It's not a secret anymore!