Results 1 to 3 of 3

Thread: what is OverLoading and OverRiding in VB.NET

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Location
    India
    Posts
    5

    Question what is OverLoading and OverRiding in VB.NET

    Hi,

    I am newbie to VB.NET.
    Kindly explain me what is overloading and overriding
    in vb.net.How this can be achieved.
    Please explain with some good examples.
    So I will have a clear idea.


    Thanks and regards
    bali

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Overloading is basically when you have more than one method with the same name but a different number of or different types of parameters. The application then determines which one to call based on the parameters used. Showing the 'Overloads' keyword is optional as long as all of the methods either use it or don't use it.

    VB Code:
    1. 'will work
    2. Public Sub Testing()
    3. 'code here
    4. End Sub
    5.  
    6. Public Sub Testing(ByVal Filename As String)
    7. 'code here
    8. End Sub
    9.  
    10. 'this will also work
    11. Public Overloads Sub Testing()
    12. 'code here
    13. End Sub
    14.  
    15. Public Overloads Sub Testing(ByVal Filename As String)
    16. 'code here
    17. End Sub
    18.  
    19. 'but this will not because only one method uses the Overloads keyword
    20. Public Sub Testing()
    21. 'code here
    22. End Sub
    23.  
    24. Public [b]Overloads[/b] Sub Testing(ByVal Filename As String)
    25. 'code here
    26. End Sub

    Overrides is used by derived classes (classes that inherit from a base class) to replace the original method from the base class with one of its own, which must match the same method signature.

    VB Code:
    1. 'base class
    2. Public Class BaseClass
    3.  
    4. Public Overridable Sub Testing()
    5.    Msgbox("Shown from the Base")
    6. End Sub
    7.  
    8. End Class
    9.  
    10. 'derived class
    11. Public Class DerivedClass
    12.    Inherits BaseClass
    13.  
    14. Public Overrides Sub Testing()
    15.    Msgbox("Shown from the Derived")
    16. End Sub
    17.  
    18. End Class
    19.  
    20. 'then in an app
    21. Dim bc as New BaseClass()
    22. bc.Testing()
    23. Dim dc as New DerivedClass()
    24. dc.Testing()
    Last edited by Edneeis; Oct 22nd, 2002 at 01:47 AM.

  3. #3
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    I just thought I would let you know Edneeis....

    Your knowledge of this subject scares me at times.

    P.S
    Dont work to hard

    Parksie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width