Method overriding and ShadowingRSResmi Satish12yAsked May 28, 2014, 3:28 AM EDT3 answersShareLinkedInXCopy linkSavePlease explain the method overriding and shadowing concept in oops with some real life scenario .
Method overriding and ShadowingRSResmi Satish12yAsked May 28, 2014, 3:28 AM EDT3 answersShareLinkedInXCopy linkSavePlease explain the method overriding and shadowing concept in oops with some real life scenario .
Khan Abrar AhmedRank #778 · 3K reputation12y agoPosted May 28, 2014, 3:39 AM EDT0HI please refer thishttp://www.c-sharpcorner.com/UploadFile/2072a9/method-overriding-in-C-Sharp/http://www.c-sharpcorner.com/UploadFile/0c1bb2/method-oveloading-and-overriding-C-Sharp/0
VulpesRank #55 · 29.2K reputation12y agoPosted May 28, 2014, 6:45 AM EDT0Here's a simple example which contrasts overriding with shadowing. In C#, shadowing is usually called 'hiding' instead :using System;class Dog{ public string Name { get; set; } public Dog(string name) { Name = name; } public virtual string MakeNoise() { return "barks"; } public bool IsWild { get { return false; } }}class Poodle : Dog{ public Poodle(string name) : base(name) { } public override string MakeNoise() { return "yaps"; }}class Wolf : Dog{ public Wolf(string name) : base (name) { } public override string MakeNoise() { return "howls"; } // property is not virtual so can't override but can hide it new public bool IsWild { get { return true; } }}class Program{ static void Main() { Dog d = new Dog("Rover"); Poodle p = new Poodle("Lulu"); Wolf w = new Wolf("Fang"); PrintDetails(d); PrintDetails(p); PrintDetails(w); Console.ReadKey(); } static void PrintDetails(Dog d) { string wild = d.IsWild ? "wild" : "not wild"; if (d is Wolf) // use Wolf's IsWild property instead { wild = ((Wolf)d).IsWild ? "wild" : "not wild"; } Console.Write("{0} {1} and is {2}\n", d.Name, d.MakeNoise(), wild); }}The output is:Rover barks and is not wildLulu yaps and is not wildFang howls and is wild0Jignesh TrivediRank #16 · 50.3K reputation12y agoPosted May 28, 2014, 8:15 PM EDT0hi,Please refer below link it is very good articlehttp://msdn.microsoft.com/en-us/library/ms172785.aspxhope this will help you.0Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputation12y agoPosted May 28, 2014, 8:15 PM EDT0hi,Please refer below link it is very good articlehttp://msdn.microsoft.com/en-us/library/ms172785.aspxhope this will help you.0
Khan Abrar AhmedRank #778 · 3K reputationPosted May 28, 2014, 3:39 AM EDT
http://www.c-sharpcorner.com/UploadFile/2072a9/method-overriding-in-C-Sharp/
http://www.c-sharpcorner.com/UploadFile/0c1bb2/method-oveloading-and-overriding-C-Sharp/
VulpesRank #55 · 29.2K reputationPosted May 28, 2014, 6:45 AM EDT
The output is:
Jignesh TrivediRank #16 · 50.3K reputationPosted May 28, 2014, 8:15 PM EDT
Please refer below link it is very good article
http://msdn.microsoft.com/en-us/library/ms172785.aspx
hope this will help you.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts