Advantage of Method Overriding [Resolved]

Posted by krrishbiju-15589 under C# on 12/5/2013 | Points: 10 | Views : 9044 | Status : [Member] | Replies : 8
Hi,
Can anyone help me on this,

What is the advantage of Method Overriding while we can make new method instead of override of existing method??

Regards
krrish




Responses

Posted by: vishalneeraj-24503 on: 12/5/2013 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Let's take an example:-

//Here your Base class,which contains Display method,you can Override this method in Derived class as shown below:-
public class Base_Class
{
public Base_Class()
{

}

public virtual void display()
{
Console.WriteLine("base class");
}
}


//Here your Derived class
public class Derive_Class:Base_Class
{
public Derive_Class()
{

}

public override void display()
{
Console.WriteLine("derive class");
}
}

We can override existing method,and write our own Logic in Dereved class.

As you can see in the derived class,i have override method display.
So you can also override your own method and write own logic.

krrishbiju-15589, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/5/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Please go through below links:-
http://social.msdn.microsoft.com/Forums/vstudio/en-US/b807b077-9e0f-4e51-be5a-4445736f5560/what-is-the-advantage-of-method-overriding-while-we-can-make-new-method-instead-of-override-of?forum=csharpgeneral
http://www.nullskull.com/q/10036180/whats-the-benefit-i-get-if-i-use-method-overriding-.aspx
http://wiki.answers.com/Q/What_are_the_advantages_of_method_overriding#slide1
http://www.codeproject.com/Articles/18734/Method-Overriding-in-C

krrishbiju-15589, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/5/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Also go:-

http://stackoverflow.com/questions/11601093/advantages-and-disadvantages-of-method-hiding-in-c
http://www.programcall.com/25/csnet/method-overriding-in-csnet.aspx

krrishbiju-15589, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: krrishbiju-15589 on: 12/5/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Vishal,
Thanks for your replay....
Can you please explain the concept with simple examples...and please avoid this link sharing.
Regards
krrish



krrishbiju-15589, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 12/5/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
The main region is that The derived class or sub class can have its own business logic in it. Say for example, considering a real time example.
Let us say we have a class where some features of bank transactions are defined.
Now, we want to write our own bank transactions using already existing methods defined in the class but extending its behaviiour and with some modifications.
This is the sitaution where we inherit the class and overrride the methods which are required to suit our business requirement.

Hope you got it.


If this helps you towards the solution, click on MARK IT AS ANSWER

Happy Coding.

krrishbiju-15589, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/5/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi did you find solution?

krrishbiju-15589, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amatya on: 2/5/2016 [Member] Bronze | Points: 25

Up
0
Down
Visit The Blog
http://adityagupta200.blogspot.in/

Feel free to share informations 9731764134
Thanks

krrishbiju-15589, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amatya on: 2/5/2016 [Member] Bronze | Points: 25

Up
0
Down
http://adityagupta200.blogspot.in/
Visit Above Blog

Feel free to share informations 9731764134
Thanks

krrishbiju-15589, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response