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 3980782
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:19:54+00:00 2026-05-20T05:19:54+00:00

I have gone through various questions about public inner classes in this forum, however

  • 0

I have gone through various questions about public inner classes in this forum, however I didn’t see any answer for what I am trying to find, so yet again another question about Java Public Inner Classes. I am reviewing another developer’s code and this person has made use of a lot of inner classes. Here’s an example

    public class A{
              private class B
              private class C
              private class D
              :
              :

    public class B{
    }

    public class c{
    }

    public class D{
    }
}

So when I asked the developer about why she used inner classes, she told me, since these classes are going to be ONLY used by this class, she did it this way, which I agree is a valid reason,

However the class has become a “long” (around 200 lines of getters and setters including 4-5 class definitions) class, with bunch of inner classes. Though I agree with her reason, I am concerned about the length of the class. I almost feel like telling her to remove the inner classes and make them classes of their own, but for now, the only advantage of doing this is it reduces the size of the class.

I personally avoid using inner classes, it might just be a habit or I am just dogmatic when it comes to this, so I don’t want my personal bias to dictate the review. That’s why, I would like to know from you guys, what other advantages or disadvantages are there of what I am proposing? (i.e. move them to their own classes) Thanks.

  • 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-20T05:19:55+00:00Added an answer on May 20, 2026 at 5:19 am

    The only difference I know is that inner classes can access private instance variables of the outer class. The use of private inner classes prevents access from other classes, too.

    From oracle java tutorial:

    Logical grouping of classes—If a class is useful to only one other class, then it is logical to embed it in that class and keep the two together. Nesting such "helper classes" makes their package more streamlined.

    Increased encapsulation—Consider two top-level classes, A and B, where B needs access to members of A that would otherwise be declared private. By hiding class B within class A, A’s members can be declared private and B can access them. In addition, B itself can be hidden from the outside world.

    More readable, maintainable code—Nesting small classes within top-level classes places the code closer to where it is used.

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

Sidebar

Related Questions

I've gone through all of the various questions on this, but none have fixed
Have gone through several questions on this topic at SO, and am unable to
Have gone through hibernate api specification on FlushMode but didn't get the exact difference.
I have gone through this to change the color of my title bar. I'm
I have gone through this page... http://www.php.net/manual/en/function.hash.php MD5 is 32 characters long while sha1
I have gone through a couple of similar questions but could reach a definite
I have gone through the fadein/fadeout tutorial that is on this page: For the
I have gone through many posts on SO regarding this issue: Tried everything in
I have gone through different questions/articles on Message Brokers and ESBs(Even on stackoverflow). Still
I have gone through this and this , but the question I am asking

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.