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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:34:40+00:00 2026-06-09T18:34:40+00:00

All – Have read various articles on the new keyword and when it should

  • 0

All –

Have read various articles on the new keyword and when it should be used:

MSDN – http://msdn.microsoft.com/en-us/library/6fawty39(v=vs.80).aspx

StackOverflow – benefit of using new keyword in derived class member having same name with base class member

Here is a sample code I have written to practice this concept

    static void Main(string[] args)
    {
        Animal a2 = new Dog();
        a2.Talk();
        a2.Sing();
        a2.Greet();
        a2.Dance();
        Console.ReadLine();
    }

class Animal
{
    public Animal()
    {
        Console.WriteLine("Animal constructor");
    }

    public void Talk()
    {
        Console.WriteLine("Animal is Talking");
    }

    public virtual void Sing()
    {
        Console.WriteLine("Animal is Singing");
    }

    public void Greet()
    {
        Console.WriteLine("Animal is Greeting");
    }

    public virtual void Dance()
    {
        Console.WriteLine("Animal is Dancing");
    }
}

//Derived Class Dog from Animal
class Dog : Animal
{
    public Dog()
    {
        Console.WriteLine("Dog Constructor");
    }

    public new void Talk()
    {
        Console.WriteLine("Dog is Talking");
    }

    public override void Sing()
    {
        //base.Sing();
        Console.WriteLine("Dog is Singing");
    }

    public new void Dance()
    {
        Console.WriteLine("Dog is Dancing");
    }
}

Any my output is coming as follows:

enter image description here

Whats confusing me is that by using the new keyword in the derieved class is actually showing an output of the base class. Isnt that wrong – isnt new keyword supposed to hide the base class membership so the result for Animal is Talking and Animal is Dancing should not be printed.

Thanks

  • 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-09T18:34:42+00:00Added an answer on June 9, 2026 at 6:34 pm

    The “new” means the method is “new” and not an “override”. Therefore, if you call a method by that name from the base, it hasn’t been overriden so the derived won’t be called.

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

Sidebar

Related Questions

All, In Apple's sample code DateCell http://developer.apple.com/library/ios/#samplecode/DateCell/Introduction/Intro.html the ivar pickerView is declared in MyTableViewController.h
All of the guides and tutorials that I have read tell me to do
All -- I have these two methods in one of my classes: public static
All my files can be found on GitHub: https://github.com/Integralist/Passage (just in case you need
All the guys probably will recommend that I read the follow previously question in
All, I have some script tags that are not working in Wordpress. If I
All, Say I have the following bit of code: select: function(start, end, allDay) {
All, I have the following date: Wed Feb 01 2012 09:30:00 GMT-0600 (Central Standard
All, I have the following code: $fetch = mysql_query(SELECT * FROM calendar_events where event_status='booked'
All the examples of use and tutorials I have found on beginBackgroundTaskWithExpirationHandler: show how

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.