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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:16:20+00:00 2026-06-05T22:16:20+00:00

How come I can’t access the hidden instance variable a in the line (int

  • 0

How come I can’t access the hidden instance variable a in the line (int gimmeValue = shinyNewBObject.a;) ? I understand that I can use the base keyword to access the instance a. However, I thought that the compiler would use the object reference in shinyNewBObject to rule out static variables. If the static version of a is ruled out, the instance version of a would become unhidden and therefore accessible.

What’s going on here? Did the compiler create a list of all a identities in the assembly and ruled out the instance variable because it’s hidden before it ruled out the other a because it’s static?

class A
{
    public int a;
}

class B : A
{
    new public static int a;

    public void m()
    {
        B shinyNewBObject = new B();
        int gimmeValue = shinyNewBObject.a; //Error
        gimmeValue = base.a;
    }
}
  • 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-05T22:16:22+00:00Added an answer on June 5, 2026 at 10:16 pm

    I think I found the answer:

    I needed to look at the member look-up section of the specification (7.4).

    “the effect of the look-up rules is simply that derived members hide base members with the same name or signature. Such single-inheritance look-ups are never ambiguous.”

    I think what happens when aobj.a is considered by the compiler is aobj is ignored for the time being and just a is considered.

    The compiler goes to the A class definition which has all of the static and instance members implicitly or explicitly and sees the two a members. Both are accessible based on (3.5) so they go in the set of possibilities. Then the hidden variable is removed leaving the static one.

    Finally ‘aobj’ is considered and an error occurs because an instance reference can’t access the static variable.

    There might be some problems with my story. If so, please correct me because I made some guesses.

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

Sidebar

Related Questions

How come you can't use the Class's traversing methods with variable's to set the
I have a variable containing a string. The string can come in several ways:
I'm trying to write a function that takes multiple arguments, which can come either
Does anyone know where I can come by a regex that matches any valid
I'm new to nodejs, the only way that I can come up with is
How come I can use += on a string, but I cannot use -=
How come I can't use normalizer function? I am using it exactly as I
This was my attempt. The best that I can come up with is getting
Using GScript for example, is there any harm that can come to a phone
Can I use an Interlocked.* synchronization method to update a DateTime variable? I wish

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.