Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What is difference between method overriding and method hiding in c#, explain with example?

user-image
Question ajoutée par Mukhtar Ahmad
Date de publication: 2014/08/20
Zubair Ali
par Zubair Ali , Software Developer III , S&P Global

Common thing is that you create a method with same signature in Base and the child class. but both have a distinction of Keyword Virtual and Override used with Base class and the child one respectively.If you just write a method in base class and in the child also with the same name then it is an example of method hiding. but if you make your method virtual in base class and override it in child class with DISTINCT implementation in child then its an example of Method Overriding. 

Dileep DK
par Dileep DK , Head of Engineering – Consumer Finance , DBS Bank Ltd.

Overriding and hiding are very similar but the differences are in the scope. When overriding you still get to access the base methods whereas while hiding you have to implement all methods.

More Questions Like This