Skip to content
Loading
  • Sachin Singh
    +2
    Yes,@Rajnikant sir, method hiding gives us the opportunity to change the method signature, and thus with the same name we can completely redifine the method.
    +2
  • Gurpreet Arora
    +2
    read it from here 
     
    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/knowing-when-to-use-override-and-new-keywords
    +2
  • Sachin Singh
    +1
    You must be already knowing what they do, both do the same thing that is reimplementing a parent class method in the child class. Then the question that arises is what is the difference then?
    Override means reimplement the method in the child class with the permission of the parent.
    Hiding means reimplement the method in the child class without the permission of the parent.
    as in the first case, the parent knows that his method is now overridden by the child class, so you call the child class method with the parent class reference then also the child method executes.
    1. Parent p= new Child();
    2. p.Method(); // child class method will execute
    3. // because parent know that yes I only had given the permission to the child //class, so he reimplemented the method.
    but in the case of method hiding, the parent doesn't know that a child has re-implemented his method. so if you call the child method with the parent reference then the parent method executes and not the child method.
    1. Parent p= new Child();
    2. p.Method(); // parent class method will execute
    3. //because the parent had never given him the permission to override the method, the child forcefully overidden the parent's method.
    +1
  • +1
    Sorry, still don't understand. Can you give an example of "completely redefine the method" compared to "redefine implementation" only? 
    Thanks 
    +1
  • Sachin Singh
    +1
    Yes, in method overriding you just re-implement the method, in method hiding too you re-implement the method then why is it called complete redefine?
    The answer is because in case of method hiding a new memory location is created, understand the point that it causes a reference type but in overriding, it simply modifies the implementation, doesn't create a new, yes a brand new method. 
    as the parent doesn't know that his method ever will be re-implement by a child how would it be possible to modify the method without creating a new one, so we have method hiding.
    +1