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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:38:58+00:00 2026-06-13T22:38:58+00:00

In the text I’m working through, the author shows a code example using a

  • 0

In the text I’m working through, the author shows a code example using a static nested class, and then comments that if the static nested class “bothers you”, you can write it as a separate class.

Why would it bother you? What are the disadvantages of using a static nested class in Java?

  • 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-13T22:38:59+00:00Added an answer on June 13, 2026 at 10:38 pm

    Advantage:
    What the author meant was a static nested class gets compiled into a totally separate .class than the outer class enclosing it. So, if it bothers you or over complicates the things or confuses you then better use it separately.
    A Static nested class doesn’t depend on the outer class instance, it can run on it’s own. Even a main function can be written inside the static nested class and invoked directly. And the benefit of it is you can have less number of objects created at runtime which wouldn’t be the case with other types of nested classes.

    Disadvantage
    The only disadvantage I can think of is a static nested class has access to both the protected and private members of the outer class.
    Say you have a class X and a class Y. In order for Y to access X’s private members but not the rest of the world, making Y an Inner class of X helps. That satisfies the encapsulation thing by grouping them together.

    But a Static Nested class doesn’t care about accessibility modifiers of the Outer class while accessing it’s members. Since it can live independently, it can allow somebody from outer world to mingle with the private members of the Outer class and hence break the encapsulation.

    Treat the Static nested class as another top level class who can gain access to the private and protected members of the Outer class without using the Outer class’s context/instance and freely sell them to external world for bad use.

    For better understanding about Nested classes or anything in Java, I would recommend going through the Oracle docs before reading any book, http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html

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

Sidebar

Related Questions

Some text before the code so that the question summary isn't mangled. class Tree
text with apstrophe is not working in the twitter. Now i am using this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Text files seem to be alright. Here is the code that is used to
Text on my page look blurry on Safari, Opera and Chrome: http://testowa.portalo.pl/wiadomosci.php I'm using
text = urllib.urlopen('www.text.com').read() frase = re.search(your text here(.*), text).group() With these code, I get
Text gets accumulates piecemeal before being sent to client. Now we use own class
Text : aaaa Pattern : aa then will two match: aa(0,1), aa(2,3) if I
Text align as tabs in < li > that read (i) Article and so
Example text (I've highlighted the desired / 's): pair[@Key=2] / Items / Item[Person/Name='Martin'] /

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.