Wednesday 19 August 2015

What is difference between Overriding and Method hiding in C#.Net

     A parent class method can be redefined under it's child class using two different approaches.
  1. Method Overriding.
  2. Method Hiding.
                       In Method overriding parent class gives the permission for it's child class to override the method by declaring it as virtual. Now the child class can override the method using the Override keyword as it got permission from parent.
                      In Method Hiding also parent class methods can be redefine under child classes even if they were not declared as Virtual by using 'new' keyword.

Example :
                 loadparent:
                public void test()
           -----------------------------------
               loadchild : loadparent
                public new void test()


No comments:

Post a Comment