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

  • Home
  • SEARCH
  • 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 3302152
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:49:21+00:00 2026-05-17T20:49:21+00:00

This is confusing to me please expalin me the behaviour of this? A declaration

  • 0

This is confusing to me please expalin me the behaviour of this?

A declaration of a new member hides an inherited member only within the scope of the new member.
Copy

**class Base
{
   public static void F() {}
}
class Derived: Base
{
   new private static void F() {}   // Hides Base.F in Derived only
}
class MoreDerived: Derived
{
   static void G() { F(); }         // Invokes Base.F
}**

In the example above, the declaration of F in Derived hides the F that was inherited from Base, but since the new F in Derived has private access, its scope does not extend to MoreDerived. Thus, the call F() in MoreDerived.G is valid and will invoke Base.F.

I am not understanding that how static void G() { F(); } can access the base class f method when it can access all methods of it’s immediate super class and super class hides the f method of base class

  • 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-17T20:49:22+00:00Added an answer on May 17, 2026 at 8:49 pm

    MoreDerived cannot access all methods of its super class; in particular, it cannot access private methods. In C#, anything marked private in a class is invisible to anything outside of that class. In other words, adding or removing a private method will not change how anything outside of that class compiles. Since the new private static void F is invisible to the outside world, MoreDerived is unaffected by it.

    If the modifier was protected instead, MoreDerived would see it.

    In the example you gave, the new keyword only changes the meaning of names in the namespace. It does not change what methods are available. A method of Derived can still call Base.F() like so:

    class Derived: Base 
    { 
       new private static void F()
       {
           F();      // calls Derived.F()
           Base.F(); // calls Base.F()
       }
    } 
    
    class MoreDerived: Derived 
    { 
       static void G() 
       {
           F();         // Invokes Base.F
           Derived.F(); // Invokes Base.F because Derived.F is private
           Base.F();    // Invokes Base.F
       }
    }
    

    It’s analogous to this example:

    class Foo
    {
        int bar; // in most methods, this variable can be accessed as just "bar"
    
        Foo(int bar) // this parameter will hide the instance member bar
        {
            this.bar = bar; // instance method can still be accessed, though
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you please explain this code? It seems a little confusing to me Is
This has been confusing me for some time. With the advent of UTF-8 as
This is a little confusing to explain, so bear with me here... I want
OK, this might sound a bit confusing and complicated, so bear with me. We've
MSDN provides a digit placeholder example: 1234.5678 (#####) -> 1235 I found this confusing
Can someone please explain what this means? Enum<T extends Enum<T>> This seems like a
Can anyone please explain how this works #define maxMacro(a,b) ( (a) > (b) )
I find this behavior of TryCast in .NET 4.0 / VS 2010 rather confusing.
I have found this example on StackOverflow: var people = new List<Person> { new
This is a bit of a long shot, but if anyone can figure it

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.