Method Overloading:

  • Whenever the definition of the base class is modified at the derived class then it is said to be method overriding.

  Method overloading  

  • If you want to change the definition then you must use the keyword “Overrides” Overrides change the definition of the base class.  

Note:

In order to modify the definition of the base class at the derived class then the method should be prefixed with the “Overrides” keyword.  

Note:

If any method is defined using the “Overrides” keyword at the derived class then the method should be prefixed with the “Overridable” keyword at the base class.  

Note:

If any method is prefixed with the “Overridable” keyword at the base class then it is not mandatory to redefine the definitions at the derived class.

‘‘Demo on Method Overriding

Imports system

Module Method Overriding ‘‘Demo

Class Parents

Public Overridable sub-MyProperty ( )

Console.WriteLine (“Use property for business”)

End sub

End class

Class Children overrides sub-MyProperty ( )

MyBase.My property ( ) invokes the base class my property method

Console.WriteLine (“Use the property for charity”)

End sub

End class

Sub main ( )

Dim c as New Children

C.MyProperty ( )

End sub

End Module  

Inclined to build a profession as VB.Net Developer? Then here is the blog post on, explore VB.Net Training

Shadowing:

It is used to maintain two definitions at the derived class such that one definition can be shadowed in order to project the other definition i.e., the definition of the base class can be shadowed in order to project the new definition provided at the derived class and vice versa is also applicable.

  Shadowing    

Observation:

  • In order to shadow the definition at the derived class shadows keyword should be used.
  • If an object is created for the derived class then the definition provided at the derived class will be projected.
  • In order to retrieve the definition of the base class using the derived class object.

 To Do:

  • Define a variable for the base class
  • Create an instance for the derived class and assign to the base class variable invoke the members using the base class variable.

‘‘Demo on Shadowing

Imports system

Module Shadowing ‘‘Demo

Class Parents Public sub-MyProperty ( )

Console.WriteLine (“Use the property for business”)

End sub

End class

Class children

Inherits Parents

Public Shadows sub-MyProperty ()

Console.WriteLine (“Use property for charity”)

End sub

End class

Sub main ( )

Dim c as New Children

C.MyProperty ( )

Dim P as Parents

P.MyProperty ( )

End sub

End Module  

For an in-depth knowledge, click on below