5
In a way it is already answered in How "new" and "virtual" work in C#?. Only it’s C there#.
Overrides
in VB.NET is the same override
of C#. AND Shadows
is the same as new
as a method modifier.
Summarizing what is already in C’s answer#:
Overrides
indicates to the compiler that you want to overwrite the implementation of a virtual method declared in the base class used in the current inheritance. So you can only use if the class is inheriting from another and has a virtual method in it with the same signature that the method you are writing in the new class. That is, you are wanting replace polymorphically the existing method.
Shadows
does something that seems to be the same, but in fact it overrides the method that is in the base class. It says to ignore that method and use that one. In theory the language could do this without any modifier, so much so that its use is not mandatory, but the compiler asks you to put something to say that you know what you’re doing and it’s intentional. So avoid mistakes by carelessness.
The consequences of this can be seen in the explanation of C’s question# linked above.
Read the documentation linked (in the keywords) it is fundamental to fully understand the use of them.
Feature | Shadowing | Overriding |
---|---|---|
Purpose | Hide and replace an existing method in the database | Polymorphically replace an existing method in the base |
Elements to be redefined | All declarable | Function, Sub, Operator, Property |
Elements that can redefine | All | All with the same signature |
Access level can be reset | Yes | Not |
Control redefinition of the derivative | Not | Can Mustoverride, Overridable, Notoverridable |
Reset read/write permission | Yes | Not |
Keyword in the base | Unnecessary | Mustoverride or Overridable mandatory |
Keyword in derivative | Shadows is only recommended | Overrides are mandatory |
Inheritance of the derivative | Keeps shading | Keep the envelope on |