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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:42:47+00:00 2026-05-15T00:42:47+00:00

Consider you have the following class public class OuterClass { … private static class

  • 0

Consider you have the following class

public class OuterClass {
    ...

    private static class InnerClass {
         int foo;
         int bar;
    }
}

I think I’ve read somewhere (but not the official Java Tutorial) that if I would declare the static member classes attributes private, the compiler had to generate some sort of accessor methods so that the outer class can actually access the static member class’s (which is effectively a package-private top level class) attributes.

Any ideas on that?

  • 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-15T00:42:47+00:00Added an answer on May 15, 2026 at 12:42 am

    Yes that’s true. At least for the Sun javac. Have a look at the following example:

    public class OuterClass {
    
        public static void main(String... args) {
            InnerClass.foo = 7;
            System.out.println(InnerClass.foo);
        }
    
        private static class InnerClass {
             private static int foo;
             private static int bar;
        }
    }
    

    $ javap -c OuterClass\$InnerClass
    Compiled from "OuterClass.java"
    class OuterClass$InnerClass extends java.lang.Object{
    static int access$002(int);
      Code:
       0: iload_0
       1: dup
       2: putstatic #1; //Field foo:I
       5: ireturn
    
    static int access$000();
      Code:
       0: getstatic #1; //Field foo:I
       3: ireturn
    
    }
    

    It defines a static int access$002(int) for setting the value, and a static int access$000() for getting the value. The setter also returns the value, presumably to easily compile someVariable = InnerClass.foo = 5.


    $ javap -c OuterClass
    Compiled from "OuterClass.java"
    public class OuterClass extends java.lang.Object{
    public OuterClass();
      Code:
       0: aload_0
       1: invokespecial #1; //Method java/lang/Object."<init>":()V
       4: return
    
    public static void main(java.lang.String[]);
      Code:
       0: bipush 7
       2: invokestatic #2; //Method OuterClass$InnerClass.access$002:(I)I
       5: pop
       6: getstatic #3; //Field java/lang/System.out:Ljava/io/PrintStream;
       9: invokestatic #4; //Method OuterClass$InnerClass.access$000:()I
       12: invokevirtual #5; //Method java/io/PrintStream.println:(I)V
       15: return
    
    }
    

    At line 2 and at line 9 it calls the setter (access$002) and getter (access$000) respectively.


    Note also that it only introduces these accesser methods if they are needed. The bar field for instance, was never accessed from outside the class, thus the compiler only generated a getter/setter for the foo field.

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

Sidebar

Ask A Question

Stats

  • Questions 425k
  • Answers 425k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The problem is that the SharePoint workflow initiation form caches… May 15, 2026 at 12:17 pm
  • Editorial Team
    Editorial Team added an answer First of all, Spring will help you to organize your… May 15, 2026 at 12:17 pm
  • Editorial Team
    Editorial Team added an answer I'm guessing it's to do with the fact that orderItems… May 15, 2026 at 12:17 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.