VB.Net program to demonstrate the method overloading based on a different order of arguments

Here, we are going to demonstrate the method overloading based on a different order of arguments in VB.Net.
Submitted by Nidhi, on December 25, 2020 [Last updated : March 06, 2023]

Method overloading based on a different order of arguments in VB.Net

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

Program/Source Code:

The source code to demonstrate the method overloading based on a different order of arguments is given below. The given program is compiled and executed successfully.

VB.Net code to demonstrate the example of method overloading based on a different order of arguments

'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
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1. Here, we created a class Sample that contains two Add() methods to calculate the sum of arguments based on a different order of arguments.

The Main() method is the entry point for the program, here we created an object of Sample class and then called both methods that will print the addition of arguments on the console screen.

VB.Net Basic Programs »






Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.