The MyClass Keyword

 The MyClass keyword allows you to call an Overridable method implemented in

Your class and make sure that implementation  of the method in this class is called rather than

An overridden method in a derived class.


  • MyClass is a keyword, not a real object.  MyClass cannot be assigned ta a variable,

Passed to procedures.

  • MyClass refers to the containing class and its inherited members.
  • MyClass can be used as a qualifier for shared members.
  • MyClass cannot be used in standerd modules.
  • MyClass can be used to qualify a method that is defined in a base class and that has no

Implementation of the method provided in that class. Such a reference has the same meaning.

As MyBase. Method.




‘ The following rules apply to overriding methods. You can only override members that are marked with the

overridable  keyword in their base class. Properties and methods are NotOverridable  by default.

Overeidden members must have the same arguments as the inherited members from the base class.

The new implementation of a member can call original implementation in the parent class by specifying

MyBase before the method name.’


Module ModuleOverride

Sub Main()

                   Dim p As Payroll

                   Dim b As BonusPayroll

                   Dim h As Decimal = 40

                   MsgBox(“Normal pay is: “ & p.PayEmployee(h))

                   MsgBox(“Pay with bomus is” “ & b.PayEmployee(h))

          End Sub

End Module

Class Payroll

          Const pr as decimal=20

          Overridable Function PayEmployee(ByVal h as Decimal) as Decimal


End Function

End Class


Class BonusPayroll

          Inherits Payroll

          Const br as decimal=10

          Overrides function PayEmployee(byval h as decimal) as decimal


          End function

End class

Average Rating (0)
by hetal   more  in VB.Net  on 3/25/2015 12:36:23 AM  

Post Your Comment