Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - 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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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: 4 stars4 stars4 stars4 stars4 stars / 12
    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


    Overloading and Overriding in Visual Basic.NET 2005 - A sample class with constructor overloading


    (Page 3 of 5 )

    Overloading is not limited only to methods. We can even overload constructors, properties, and so forth. The following is a rewrite of the above class which includes both method and constructor overloading:

    Public Class Sample3

      Private _x As Double

      Private _y As Double

     

      Public Sub New()

     

      End Sub

     

      Public Sub New(ByVal a As Double)

        _x = a

        _y = a

        'Me.SetValues(a)

      End Sub

     

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

        _x = a

        _y = b

        'Me.SetValues(a, b)

      End Sub

     

      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 from the comments in the above class, I am trying to call overloaded methods from overloaded constructors, which is possible.

    The following is the code to test the constructors in the above class:

    Dim obj As New Sample3(10, 20)

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

     

    Dim obj2 As New Sample3(10)

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

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Hello guys,This is an article for the persons who always confuse about...
       · this is very good document for the ovverloading and overriding thanks to the...
       · this is nice for beginners as it provides good explanation for the two
       · Hi Jag, My thanks, this is great to patch a few holes in my theory its...
     

    VISUAL BASIC.NET ARTICLES

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek