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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:28:59+00:00 2026-06-14T12:28:59+00:00

public class MyClass { public int myclassMember=NestedClass.nestedclassMember; //Compiler error,static reference to a non-static field

  • 0
public class MyClass {
public int myclassMember=NestedClass.nestedclassMember; //Compiler error,static reference to a non-static field

    public static class NestedClass {
        public int nestedclassMember=myclassMember; //Compiler error,static reference to a non-static field.
        public NestedClass() {
       }
    }

}

But at the same time,the following is totally legal,after removing the compile-time errors of course -:

MyClass.NestedClass nestedInstance= new MyClass.NestedClass();

What gives?How can the class be both static and non static at the same time?

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

    static doesn’t mean the same thing in this context as what it means for fields and methods.

    A static nested class is a class that doesn’t need any outer class instance to be created.

    A non-static nested class needs an instance of its outer class to be created, and has an implicit reference to this instance (available using TheNameOfTheOuterClass.this inside the inner class).

    Static inner classes are typically used to avoid exposing classes to the outside when they’re used only by one class, or to have a class being able to access private fields and methods of an outer class, or to scope a class to another one, because it’s tightly linked to it.

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

Sidebar

Related Questions

class MyClass { public: void method2() { static int i; ... } }; Will
Assuming public class MyClass { public int ID {get; set; } public string Name
I have class with collection as below public class MyClass:IXmlSerializable { int vesrion; private
I have a class like this: class MyClass{ public: MyClass(int Mode); private: std::map <
Consider the following: class MyClass { public: int operator ()(int a, int b); };
Say I have this class: class myclass { public int Field1{ get; set; }
Let's say a program like this: class MyClass { public int Numbers; public char
I have the following pattern: template <int a, int b> class MyClass { public:
public class MyClass { int i = 0; string str = here; MyStruct mystruct;
if I have class : public class myclass{ public int calc(int var1,int var2){ return

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.