VB.Net Program to Demonstrate the Method Overloading With Type Promotion

You are currently viewing VB.Net Program to Demonstrate the Method Overloading With Type Promotion

VB.Net program to demonstrate the method overloading with type promotion

'VB.net program to demonstrate the method overloading with type promotion.

Module Module1
    Class Sample
        Public Sub Add(ByVal num1 As Integer, ByVal num2 As Long)
            Dim sum As Integer = 0

            sum = num1 + num2
            Console.WriteLine("Sum is: {0}", sum)
        End Sub

        Public Sub Add(ByVal num1 As Integer, ByVal num2 As Integer, ByVal num3 As Integer)
            Dim sum As Integer = 0

            sum = num1 + num2 + num3
            Console.WriteLine("Sum is: {0}", sum)
        End Sub
    End Class
    
    Sub Main()
        Dim obj As New Sample()

	 Dim num1 As Integer = 10
        Dim num2 As Integer = 20
        Dim num3 As Integer = 30

        obj.Add(num1, num2)
        obj.Add(num1, num2, num3)
    End Sub
    
End Module

Output

Sum is: 30
Sum is: 60
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply