Search | Contact | Link To Us  

      VB .NET      

.NET Defined
OOP with VB
VB Language
Win Forms
Windows Controls
ADO .NET
User Controls
File Handling
Multithreading
Deployment
XML Web Services Essential XML
Resources
Discussions
ASP.NET
About



Advertisement












     Home> OOP with VB> Polymorphism

OOP with VB 

Polymorphism

Polymorphism is one of the crucial features of OOP. It means  "one name, multiple forms". It is also called as Overloading which means the use of same thing for different purposes. Using Polymorphism we can create as many functions we want with one function name but with different argument list. The function performs different operations based on the argument list in the function call. The exact function to be invoked will be determined by checking the type and number of arguments in the function.

The following code demonstrates the implementation of Polymorphism.

Module Module1

Sub Main()
Dim two As New One()
WriteLine(two.add(10))
'calls the function with one argument
WriteLine(two.add(10, 20))
'calls the function with two arguments
WriteLine(two.add(10, 20, 30))
'calls the function with three arguments
Read()
End Sub

End Module

Public Class One
Public i, j, k As Integer

Public Function add(ByVal i As Integer) As Integer
'function with one argument
Return i
End Function

Public Function add(ByVal i As Integer, ByVal j As Integer) As Integer
'function with two arguments
Return i + j
End Function

Public Function add(ByVal i As Integer, ByVal j As Integer, ByVal k As Integer) As Integer
'function with three arguments
Return i + j + k
End Function

End Class

Output of the above code is shown in the image below.

  Privacy Policy | Terms of Use | Site Map | Contact

  © 2004-2007 Startvbdotnet.com. All rights reserved.