Monday, May 18, 2009

Polymorphisam in Vb.Net

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

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:
10
30
60

No comments:

Post a Comment