GeekInterview.com
Series: Subject:
Question: 65 of 271

what is shadowing in .net?

Asked by: raja2020_it | Member Since Nov-2005 | Asked on: Nov 18th, 2005

View all questions by raja2020_it   View all answers by raja2020_it

Showing Answers 1 - 6 of 6 Answers
rejumgeorge

Answered On : Nov 19th, 2005

View all answers by rejumgeorge

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

  
Login to rate this answer.
samiksc

Answered On : Jan 19th, 2006

View all answers by samiksc

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.

  
Login to rate this answer.
M.Sami

Answered On : Apr 6th, 2006

View all answers by M.Sami

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

  
Login to rate this answer.
Rituparno

Answered On : 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

  
Login to rate this answer.
hari krishna

Answered On : 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

  
Login to rate this answer.
Gaurav

Answered On : 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.

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.