VB.NET Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Visual Basic Tutorial
Introduction
Installation
Creating Project
Saving a Project
Compile, Run a Project
Open an Existing Project
VB IDE
Forms
VB Datatypes
Constants
Variables
User Defined Datatypes
VB Control Structure
VB Loops
Operators
VB Controls
Dialog Controls
Console Programming
VB Objects,Classes
VB Arrays
Math Functions
String Functions
Type Conversion Functions
Date Time Functions
Databases in VB.net
Enumeration
File Handling
Debugging
Debugging Tools
Exception Handling
Samples
Feedback
 

Overriding in VB.NET

Tutorials Vbnet

Topic

What is overriding in VB.NET?



Explanation
Over riding in VB.NET

     Overriding in VB.net is method by which a inherited property or a method is overidden to perform a different functionality in a derived class. The base class function is declared using a keyword Overridable and the derived class function where the functionality is changed contains an keyword Overrides.

Example:
   Module Module1

    Class Over
       Public Overridable Function add(ByVal x As Integer, 
               ByVal y As Integer)
          Console.WriteLine('Function Inside Base Class')
          Return (x + y)
       End Function
    End Class

    Class DerOver
     Inherits Over
     Public Overrides Function add(ByVal x As Integer, 
              ByVal y As Integer)
          Console.WriteLine(MyBase.add(120, 100))
          Console.WriteLine('Function Inside Derived Class')
          Return (x + y)
     End Function
    End Class
     
    Sub Main()
        Dim obj As New DerOver
        Console.WriteLine(obj.add(10, 100))
        Console.Read()
    End Sub
  End Module
Result:
    Function Inside Base Class
    220
    Function Inside Derived Class
    110
Description:

In the above overriding example the base class function add is overridden in the derived class using the MyBase.add(120,100) statement. So first the overidden value is displayed, then the value from the derived class is displayed.







Other Links

web hosting