beingtopper.jkp@gmail.com
+91-8700702530
Free Demo

Being Topper

  • About Us
  • Knowledge Base
  • Modules
  • Branches
    • Ajmer
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us

Being Topper

  • About Us
  • Knowledge Base
  • Modules
  • Branches
    • Ajmer
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us
  • About Us
  • Knowledge Base
  • Modules
  • Branches
    • Ajmer
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us

Being Topper

  • About Us
  • Knowledge Base
  • Modules
  • Branches
    • Ajmer
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us
BCA NOTESInformation technologyPrograms/AlgorithmVB.Net progrmas

Demonstrate Polymorphism in Vb.net through Constructor overloading.

Being Topper 17/10/2014 0 Comments

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

 

Polymorphism in VB.NET. 

Polymorphism is the concept that different objects have different implementations of the same characteristic. … Given two different classes with the same properties and methods, a variable of type object could be used to instantiate an object of either class

 

Constructor overloading in vb.net

When the same method name is used for more than one method, with different types of parameters and returned types, then the method is said to be overloaded. Constructor is a special method called ‘New()’ in vb.net and is defined as a Sub.Overloading feature is used most frequently to overload the constructor. We overload the constructor by defining more than one ‘Sub New()’ procedure. By overloading a constructor, we make available more than one constructor.So, while creating an object we can choose which constructor we want to use to instantiate the object. The only condition while overloading the constructor is that the constructor should have a signature which is different from other constructors.

 

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 :

 

constructor overloading polymerphism polymerphism in vb.net WAP to demonstrate Polymorphism in Vb.net through Constructor overloading.
AboutBeing Topper
In Socials:
PrevWAP to demonstrate Polymorphism in Vb.net through Method Overloading17/10/2014
Program in VB.Net to build a class which implements an interface17/10/2014Next

Related Posts

B.tech notesBCA NOTESEvent HandlingInformation technologyJava ProgramsPrograms/Algorithm

java program for counting vowels , consonants , digits and whitespaces …

Java program for counting vowels , consonants , digits and white spaces (more…)

Being Topper 17/03/2014
BCA NOTESVB.Net progrmas

Program to demonstrate abstract class and abstract methods in VB.net.

Ques :Write a program to demonstrate abstract class and abstract methods in VB.net....

Being Topper 17/10/2014
Categories
Recent Posts
  • Best Email Marketing Software and Services
  • How to Apply Adsense on YouTube
  • Complete Guide to Writing a Newsletter !
  • Benefits of Creating Email List for small Businesses | Digital Marketing
  • Create Account or Get Email Alerts When New Employees Join a Company

Copyright © 2021 Being Topper ® . All Rights Reserved