Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8857321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:33:40+00:00 2026-06-14T14:33:40+00:00

So if I write the following code in Java: public class A extends A{

  • 0

So if I write the following code in Java:

public class A extends A{
    public static void main(String[] args){
    }
}

This gives a compiler error message cyclic inheritance involving A.

The same happens if I write two classes A and B and A inherits B and B inherits A.

This makes sense to me, as it is quite hard to imagine how this would be possible anyway.

I then asked about this from one of the professors at my uni. He said there are languages where this is possible and he lamented how this is not possible in Java and that he had done some projects where he had used cyclic inheritance and so on, but I couldn’t really understand any of it. He also mentioned he had had problems where he would have liked to use cyclic inheritance.

Can you educate me on the possible uses of this strange phenomena of cyclic inheritance? When is it possible and how? Are there problems where this could be useful?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:33:42+00:00Added an answer on June 14, 2026 at 2:33 pm

    I dug up this interesting reference: basically it says that cyclic inheritance is valid as long as there are no repeated fields, as the lookup for any field just needs to traverse one loop of the cycle to find out a meaning. If a field is repeated then none of the two definitions is more valid than the other and apparently there would be a problem.

    So suppose that you want to define a person as a human and as a voter, and set different attributes for each. In pseudo-code:

    class Person extends Human:
      String name;
    
    class Human extends Voter:
      String language;
    
    class Voter extends Person:
      Country residence;
    

    Now you can address different aspects of an individual without having to define a hierarchy, and you might instantiate different people as a Person (with name), a Human (that speaks a language) or a Voter (in a particular country). No aspect is more important than the other.

    While interesting, I don’t think it is practical to use outside of research projects. Imagine having constructors for all classes that pass parameters to the super() constructors — it would be easy to mess up the whole construct.

    Update: the given pseudocode does not compile when translated to Java 8, and apparently under any language (except Cecil as shown by the link given above). It seems that nobody found any valid uses and therefore disallowed cyclic inheritance. This does not mean that the concept is inherently impossible; just that the practical uses do not justify the effort implementing the special case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: public class Tests { public static void main(String[] args)
I wrote the following code: import java.lang.*; import DB.*; private Boolean validateInvoice(String i) {
I write the following code in simulate.jsp , to receive some String simulationInfos from
How would I write the following C# code in F#? namespace Shared { public
Using the following code to write to a file int main(int argc, char *
This is the following code: `package com.tom.jam; //import java.sql.Connection; //import java.sql.DriverManager; import java.sql.*; import
Let's take the following code: public class Test { class A { public A()
My program looks like public class TopKRecord extends Configured implements Tool { public static
I'm referring following code to download a file from particular URL. public class FileFromServerExample
I write the following code all the time to handle when the enter key

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.