Home >>VB.Net Built-in Functions >VB.Net Program of method overloading based on different order of arguments

VB.Net Program of method overloading based on different order of arguments

Write a VB.Net Program of method overloading based on different order of arguments

Here, to determine the addition of given arguments based on a different order of arguments, we can create a sample class with two overloaded Add() methods.

Program :

Below is the source code to demonstrate the overloading method based on a particular argument order. The program given is compiled and successfully executed.

'VB.net program to demonstrate the method -overloading based

'on a different order of arguments.


Module Module1
    Class Sample
        Public Sub Add(ByVal num1 As Double, ByVal num2 As Integer)
            Dim sum As Double = 0
            sum = num1 + num2
            Console.WriteLine("Sum is: {0}", sum)
        End Sub
        Public Sub Add(ByVal num1 As Integer, ByVal num2 As Double)
            Dim sum As Double = 0
            sum = num1 + num2
            Console.WriteLine("Sum is: {0}", sum)
        End Sub
    End Class
    Sub Main()
        Dim obj As New Sample()
        obj.Add(10.6, 20)
        obj.Add(10, 20.8)
    End Sub
End Module
	
Output:
Sum is: 30.6
Sum is: 30.8
Explanation:

We created a Module1 module in the program above. Here, to determine the sum of arguments based on a particular order of arguments, we created a Sample class that contains two Add() methods.

The Main() method is the program entry point, we created a Sample class object here and then called all methods to print the addition of arguments on the console screen.


No Sidebar ads