Demonstrate Polymorphism in Vb.net through Constructor overloading.

Demonstrate Polymorphism in Vb.net through Constructor overloading.

Que : WAP to demonstrate Polymorphism in Vb.net through Constructor overloading.

Imports System.Console

Module Module1

Structure areas

Public area As Integer

Public Sub display()

WriteLine("Area = " & area)

End Sub

Public Sub New(ByRef side As Integer)

area = side * side

End Sub

Public Sub New(ByVal l As Integer, ByVal b As Integer)

area = l * b

End Sub

Public Sub New(ByVal r As Double)

area = 4.13 * r * r

End Sub

End Structure

 

Sub Main()

Dim l, b, ch As Integer

Dim r As Double

WriteLine("1. Area of a Square")

WriteLine("2. Area of a Rectange")

WriteLine("3. Area of a Circle")

WriteLine("Enter Your Choice : ")

ch = ReadLine()

 

Select Case ch

Case 1

Write("Enter Size of a side : ")

l = ReadLine()

Dim s1 As areas = New areas(l)

s1.display()

Case 2

Write("Enter length : ")

l = ReadLine()

Write("Enter breadth : ")

b = ReadLine()

Dim s1 As areas = New areas(l, b)

s1.display()

Case 3

Write("Enter radius : ")

r = ReadLine()

Dim s1 As areas = New areas(r)

s1.display()

Case Else

WriteLine("Enter a Valid Choice")

End Select

End Sub

End Module

 

Output :

WAP to demonstrate Polymorphism in Vb.net through Constructor overloading.

0 Like

Leave a Reply

Your email address will not be published. Required fields are marked *
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>