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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:27:46+00:00 2026-06-18T12:27:46+00:00

Today I was reading about static nested class and I am little confused because

  • 0

Today I was reading about static nested class and I am little confused because of below code.

class testOuter {
    int x;
     static class inner {
       int innerVar; 
    public void testFunct() {
        x = 0;       // Error : cannot make static reference to non static field
        innerVar = 10;
        outerFunc(this);
     }
     }
     static void outerFunc(SINGLETON s) {
         
     }
}

What I understood about static nested class is, it behaves like a static member of outer class. It can refer only static variables and can call static methods. From the above code, the error at x=0 is fine.

But what I am confused is if its behaves like static block, then it is allowing me to modify innerVar, which is not static and also how can it have this pointer. So if the nested class is static then the method inside or not static implicitly?

  • 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-18T12:27:47+00:00Added an answer on June 18, 2026 at 12:27 pm

    Write static int x instead of int x, then it will work. As you said yourself, static inner class can access only static members of outer class. Since x is not static in your code, you can’t access it.

    P.S.

    Note, that ALL normal classes are static, i.e. one instance of class information exists per application run. So, when you declare inner class being static, you just state that it is just as normal class.

    Contrary, non-static inner classes are different. Each instance of non-static inner class is a closure, i.e. it is tied to some INSTANCE of outer class. I.e. you can’t create instance of non-static inner class without respect of some outer class instance.

    P.P.S.

    Ah sorry, you didn’t highlight this and innerVar. Both are non-static members of inner class, so you can access them. You cannot access non-static members only if they belong to OUTER class.

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

Sidebar

Related Questions

Today i was reading about pure function, got confused with its use: A function
Today I was reading about synchronization. I am a bit confused after reading that
I was reading about self-referential has_many :through data situations today, because I'm trying to
I was reading today about OOCSS which says by using that approach have 2
I started reading about underscore.js today, it is a library for javascript that adds
Today, I was reading about structures in Let Us C (on Goodreads ). I
I just began reading more about Markov Chain Generators today, and am really intrigued
While reading proggit today, I came upon this comment in a post about how
I was reading today about researchers discovering that NVidia's Phys-X libraries use x87 FP
Reading about F# today and I'm not clear on one thing: From: http://msdn.microsoft.com/en-us/library/dd233200.aspx you

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.