What is shadowing in .net?

Questions by raja2020_it   answers by raja2020_it

Showing Answers 1 - 8 of 8 Answers

rejumgeorge

  • Nov 19th, 2005
 

When two programming elements share the same name, one of them can hide, or shadow, the other one. In such a situation, the shadowed element is not available for reference; instead, when your code uses the shared name, the Visual Basic compiler resolves it to the shadowing element.Reju

  Was this answer useful?  Yes

samiksc

  • Jan 19th, 2006
 

Shadowing is either through scope or through inheritance.

Shadowing through inheritance is hiding a method of a base class and providing a new implementation for the same. This is the default when a derived class writes an implementation of a method of base class which is not declared as overridable in the base class. This also serves the purpose of protecting an implementation of a new method against subsequent addition of a method with the same name in the base class.

'shadows' keyword is recommended although not necessary since it is the default.

  Was this answer useful?  Yes

M.Sami

  • Apr 6th, 2006
 

while surfing i got very accurate and valid defination.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.http://www.codeproject.com/useritems/OSH.asp

  Was this answer useful?  Yes

Rituparno

  • Jul 1st, 2006
 

CriterionShadowingOverriding
PurposeProtecting against a subsequent base class modification introducing a member you have already defined in your derived classAchieving polymorphism by defining a different implementation of a procedure or property with the same calling sequence
Redefined elementAny declared element typeOnly a procedure (Function or Sub) or property
Redefining elementAny declared element typeOnly a procedure or property with the identical calling sequence1
AccessibilityAny accessibilityCannot expand the accessibility of overridden element (for example, cannot override Protected with Public)
Readability and writabilityAny combinationCannot change readability or writability of overridden property
Keyword usageShadows recommended in derived class; Shadows assumed if neither Shadows nor Overrides specifiedOverridable required in base class; Overrides required in derived class
Inheritance of redefining element by classes deriving from your derived classShadowing element inherited by further derived classes; shadowed element still hidden2Overriding element inherited by further derived classes; overridden

  Was this answer useful?  Yes

hari krishna

  • Dec 11th, 2006
 

The programming techniuqe of replacing a member of a base class with a new member in a derived class.Shadowing differs from overriding in that base class's shadowed member is no longer available from the derived class

  Was this answer useful?  Yes

Gaurav

  • Jul 16th, 2011
 

Shadowing is a concept of polymorphism usage in Object Oriented Programming. This is a concept related to over-riding functions at run-time or making a shadow of the object's methods in the inherited classes. Though it is not much used in programming but it may be used sometimes and its usage is very restrictive and unique.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions