Visual Basic.NET
  Home arrow Visual Basic.NET arrow Overloading and Overriding in Visual Basic...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Overloading and Overriding in Visual Basic.NET 2005
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2007-07-30

    Table of Contents:
  • Overloading and Overriding in Visual Basic.NET 2005
  • A sample class with method overloading
  • A sample class with constructor overloading
  • Method overriding in Visual Basic 2005
  • Multi-level method overriding in Visual Basic 2005 inheritance

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Overloading and Overriding in Visual Basic.NET 2005
    (Page 1 of 5 )

    This article gives you an in-depth understanding of the differences between overloading and overriding in Visual Basic.NET 2005. It is assumed that the reader knows something about object-oriented programming in Visual Basic.NET.
    Two downloadable zip files are available for this article, one on overloading and one on overriding.

    If you are new to OOP in Visual Basic.NET, I strongly suggest that you go through the following links:

    Using Constructors with Object-Oriented Database Development

    Properties and Object-Oriented Database Development

    Using Methods with Object-Oriented Database Development

    An Introduction to Object-Oriented Database Development

    The entire source code for this article is available in the form of downloadable zip files.  The solution was developed using Microsoft Visual Studio 2005 Professional Edition on Microsoft Windows Server 2003 Enterprise Edition.  I didn't really test it in any other environment.  I request that you post in the discussion area if you have any problems in execution.

    A sample class without overloading

    Before taking a direct look at overloading, let us try to understand the following class:

    Public Class Sample

      Private _x As Double

      Private _y As Double

     

      Public Property X() As Double

        Get

          Return _x

        End Get

        Set(ByVal value As Double)

          _x = value

        End Set

      End Property

     

      Public Property Y() As Double

        Get

          Return _y

        End Get

        Set(ByVal value As Double)

          _y = value

        End Set

      End Property

     

      Public Sub SetTwoValues(ByVal a As Double, ByVal b As Double)

        _x = a

        _y = b

      End Sub

     

      Public Sub SetSingleValue(ByVal a As Double)

        _x = a

        _y = a

      End Sub

     

      Public Function GetProduct() As Double

        Return _x * _y

      End Function

     

    End Class

    The above class has two private fields ("_x" and "_y") which are only accessible within the class (and not outside the class).  Further, it has two public properties and three public methods (public members are accessible even outside the class).

    The following is the sample code needed to test the above sample class:

    Dim obj As New Sample

    obj.X = 5

    obj.Y = 30

    MessageBox.Show("Product = " & obj.GetProduct())

     

    Dim obj2 As New Sample

    obj2.SetTwoValues(10, 20)

    MessageBox.Show("Product = " & obj2.GetProduct())

     

    Dim obj3 As New Sample

    obj3.SetSingleValue(10)

    MessageBox.Show("Product = " & obj3.GetProduct())

    I created three objects (or instances) for the class "Sample" named "obj," "obj2" and "obj3."  The first object uses properties to assign values.  The second object uses a method named "SetTwoValues" to assign two values.  The third object uses another method named "SetSingleValue" to assign only a single value.

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Hello guys,This is an article for the persons who always confuse about...
     

    VISUAL BASIC.NET ARTICLES

    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic
    - Manipulating Forms with the Windows Forms Li...
    - Basics of the Windows Forms Library
    - Forms, Controls, and Other Useful Objects
    - Implementing OOP to Develop Database Oriente...
    - Using Themes and Skins for Personalization w...
    - A Deeper Look at Personalization using Visua...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway