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

  • SEARCH
  • Home
  • 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 6348455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:25:18+00:00 2026-05-24T21:25:18+00:00

There are some cases in Java where an inner class extends an outer class.

  • 0

There are some cases in Java where an inner class extends an outer class.

For example, java.awt.geom.Arc2D.Float is an inner class of java.awt.geom.Arc2D,
and also extends Arc2D.
(c.f. http://download.oracle.com/javase/6/docs/api/java/awt/geom/Arc2D.Float.html)

Also, sun.org.mozilla.javascript.internal.FunctionNode.Jump extends sun.org.mozilla.javascript.internal.Node, which is a superclass of FunctionNode.
(sorry… cannot find a link to the javadoc)

To me, this seems odd. Could you then create these?

new Arc2D.Float.Float() //n.b. I couldn't get this to compile in Intellij IDEA;

new FunctionNode.Jump.Jump.Jump(1); // I could get this to compile

What purpose does it serve to have a subclass nested as an inner class of the superclass?

I wondered whether it was to access something in the superclass, but if you wanted to access any variables/methods in the parent, you could use

super.variable;

or

super.method();

Edit 1:
jjnguy has suggested it’s to keep the logic in the same place. In which case, why wouldn’t you write a file com.mypackage.AbstractTest:

abstract class AbstractTest {
  abstract String getString();
}

class ExtensionTest extends AbstractTest {
  @Override
  String getString() {
    return "hello world";
  }
}

… rather than:

abstract class AbstractTest {
  abstract String getString();

  class ExtensionTest extends AbstractTest {
    @Override
    String getString() {
      return "hello world";
    }
  }
}

Edit 2:
It has rightly been pointed out that the suggestion in my previous edit was flawed, as couldn’t construct ExtensionTest outside of the package. However, I’ve had a further think about this over the weekend, so what about the following:

abstract class Test {
  public class ExtensionTest extends AbstractTest {
    @Override
    String getString() {
      return "hello world";
    }
  }

  private abstract class AbstractTest {
    abstract String getString();
  }
} 

In essence, the best answer I’ve seen so far is that having an inner class extend its outer class allows the logic to be grouped together. However, I think that this can be done without the extension.

In my mind, it seems like bad design to have a class that can have an infinite number of the same subclasses nested within it. (Context: this came up whilst trying to produce a dictionary for a code completion utility, and threw a StackOverflowException. I found a workaround, but I just cannot understand why it had been designed that way.)

  • 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-05-24T21:25:20+00:00Added an answer on May 24, 2026 at 9:25 pm

    Have a look at Java’s Point2D. It has two inner classes that are sub-classes of it.

    The important thing to note is that they are static inner classes. This has an entirely diffenent meaning that a regular inner class. Just like a static method, a static class is defined at the class-level instead of the object level.

    In the Point2D case, it is done to logically couple the classes and their logic. It helps a user of the abstract type Point2D find an implementation that they can use.

    In response to your edit I’d like to point out 1 important fact. A single Java file may only contain one public class, except for public inner classes. While both of your examples may compile, they do not allow access to those classes to the public. If you want to present multiple public classes to someone in a single file, you must use public static inner classes.

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

Sidebar

Related Questions

I have some HTML I am trying to parse. There are cases where the
Is there some way I can use URLs like: http://www.blog.com/team-spirit/ instead of http://www.blog.com/?p=122 in
Are there some principles of organizing classes into namespaces? For example is it OK
Is there some means of querying the system tables to establish which tables are
Is there some built-in way to share files between Xen guests? I don't currently
Is there some way to block access from a referrer using a .htaccess file
Is there some way to hide the browser toolbar / statusbar etc in current
Is there some rare language construct I haven't encountered (like the few I've learned
Is there some reasonably cross platform way to create a thumbnail image given a
I was browsing some old books and found a copy of Practical Java by

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.