Home > DeveloperSection > Interviews > What is the difference between shadow and override?

Posted on    February-08-2016 11:24 PM

 C# C#  ASP.Net 
Ratings:
 2 Answer(s)
  537  View(s)
Rate this:

Anupam Mishra

Total Post:23

Points:115
Posted on    February-09-2016 12:24 AM

In general,  Overriding makes the base class method invisible. Shadowing a field only hides the field from view. we can still explicitly access the hidden shadowed field if we wish. We can't access an invisible overridden method.
When we define a class that inherits from a base class, then we are/ sometimes want to redefine one or more of the base class elements in the derived class. Shadowing and overriding are both available for this purpose.
Shadowing and overriding are both used when a derived class inherits from a base class, and both redefine one declared element with another. But there are significant differences between the two. For more details click HERE

Abhishek Maheshwari
Abhishek Maheshwari

Total Post:1

Points:5
Posted on    January-04-2017 1:30 AM

Shadowing :- This is a VB.Net Concept by which you can provide a new implementation for the base class member without overriding the member. You can shadow a base class member in the derived class by using the keyword "Shadows". The method signature,access level and return type of the shadowed member can be completely different than the base class member.

Hiding : - This is a C# Concept by which you can provide a new implementation for the base class member without overriding the member. You can hide a base class member in the derived class by using the keyword "new". The method signature,access level and return type of the hidden member has to be same as the base class member.Comparing the three :-

1) The access level , signature and the return type can only be changed when you are shadowing with VB.NET. Hiding and overriding demands the these parameters as same.

2) The difference lies when you call the derived class object with a base class variable.In class of overriding although you assign a derived class object to base class variable it will call the derived class function. In case of shadowing or hiding the base class function will be called.

Source:-  Difference between Shadowing and Overriding


Don't want to miss updates? Please click the below button!

Follow MindStick