aspose file tools*
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
Author

ClassCircularityError

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: 14144
    
  18

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 7 API documentation
Scala Notes - My blog about Scala
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.


SCJA
~Currently preparing for SCJP6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassCircularityError