Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - Overloading and Overriding in Visual Basic...
Iron Speed
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
     
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Overloading and Overriding in Visual Basic.NET 2005 - A sample class with method overloading
    (Page 2 of 5 )

    When we have ten parameters to pass, with different combinations, to methods which have similar logic, naming those methods differently from each other would be confusing when working with objects.  In such a situation, we can implement more methods with the same name and with a difference in parameters.

    A rewrite of the class in the previous section, which implements overloading (more methods with the same name and different parameters) is as follows:

    Public Class Sample2

      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 SetValues(ByVal a As Double, ByVal b As Double)

        _x = a

        _y = b

      End Sub

     

      Public Sub SetValues(ByVal a As Double)

        _x = a

        _y = a

      End Sub

     

      Public Function GetProduct() As Double

        Return _x * _y

      End Function

     

    End Class

    As you can see, for the above class there exist two methods with the same name, "SetValues," but with different parameters.  Those are called overloaded methods. The following is the code that tests the above class:

        Dim obj As New Sample2

        obj.X = 5

        obj.Y = 30

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

     

        Dim obj2 As New Sample2

        obj2.SetValues(10, 20)

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

     

        Dim obj3 As New Sample2

        obj3.SetValues(10)

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

    If you observe the "obj2" and "obj3," we are calling the same "SetValues" method.  Based on the number of parameters, and based on their data types, we are passing to the method; the respective method with the best match gets picked up and executed automatically.

    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 4 hosted by Hostway