Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Shadows' vs. 'Overrides' in VB.NET

What is the significance of the two keywords Shadows and Overrides? What they do and for which context is one or the other preferable?

like image 609
Jeff Avatar asked Jan 20 '09 21:01

Jeff


People also ask

What is the difference between shadowing and overriding?

Shadowing redefines the complete method, whereas overriding redefines only the implementation of the method. In Overriding, you can access the base class using the child class' object overridden method.. Shadowing has cannot access the chaild class methos. Shadowing is also known as method hiding.

What is shadowing in VB net?

A derived type shadows the name of an inherited type member by redeclaring it. Shadowing a name does not remove the inherited type members with that name; it merely makes all of the inherited type members with that name unavailable in the derived class.

What is overrides in VB net?

Overrides, however, can only be used in a derived class (sometimes called a child class) that inherits from a base class (sometimes called a parent class). And Overrides is the hammer; it lets you entirely replace a method (or a property) from a base class.

What is shadowing in asp net?

Shadowing is a VB.Net concept. It also known as method hiding in C#. Using this concept we can provide a new implementation for the base class method without overriding it. Overriding allows us to re-write a base class function with a different definition.


1 Answers

Overrides is the more normal qualifier. If the child class redefines a base class function in this way, then regardless of how a child object is referenced (using either a base class or a child class reference) it is the child function that is called.

On the other hand, if the child class function Shadows the base class function, then a child object accessed via a base class reference will use that base class function, despite being a child object.
The child function definition is only used if the child object is accessed using a matching child reference.

like image 169
Nick Avatar answered Oct 09 '22 09:10

Nick