SlideShare a Scribd company logo
1 of 14
1
A Programme Under the Compumitra Series
Programming Primer –
Polymorphism (Method Overloading)
LAB WORK GUIDE
2
OUTLINE
Polymorphism
 Method Overloading (using
VB)
Example Template Creation.
Code Creation.
Output Evaluation.
Example Explanation.
Error Trials.
Home Exercise.
Review Summary.
3
Polymorphism
(Method Overloading)
Using VB
Method overloading is a one of the techniques of creating multiple polymorphic
classes with variation in its number and type of parameters. For e.g.
MyMethod(param1) and MyMethod(param1, param2) are two overloaded methods
of same name but they act differently on the basis of parameters.
4
OverloadingVB– Creating Button and Label Template
Button with 'Text' Property set
to 'Method Overloading'.
Three Labels to hold the place
for output display with 'text'
property set to NULL (blank).
• Follow Standard Website Creation Steps and set your path to
C:Learner<student-id>ProgrammingPrimerOverloadingVB
• Now Create the Execution Event Handler as a button and output
place holders as follows.
5
OverloadingVB – Copy/Paste Code-1
Dim mc1 As New My_Class
Label1.Text = mc1.MyMethod()
Label2.Text = mc1.MyMethod("abc", 10)
Label3.Text = mc1.MyMethod("xyz", "lmn")
Go to 'Default.aspx.vb' by double clicking
on 'Button' ('Method Overloading' button)
of 'Default.aspx' and 'Paste' the Code in
'Button1_Click' method
Dim mc1 As New My_Class
Label1.Text = mc1.MyMethod()
Label2.Text = mc1.MyMethod("abc", 10)
Label3.Text = mc1.MyMethod("xyz", "lmn")
Copy this Code
6
OverloadingVB - Copy Code-2
Class My_Class
Public Overloads Function MyMethod() As String
Return("Output from MyMethod, which takes no parameter")
End Function
Public Overloads Function MyMethod(ByVal a As String, ByVal b As Integer) As
String
Return("Output from MyMethod, which takes two parameters, one as String
and second as Integer")
End Function
Public Overloads Function MyMethod(ByVal s As String, ByVal c As String) As
String
Return("Output from MyMethod, which takes two String type parameters")
End Function
End Class 'My_Class
Copy this Code
7
OverloadingVB - Paste Code-2
Class My_Class
Public Overloads Function MyMethod() As String
Return("Output from MyMethod, which takes no parameter")
End Function
Public Overloads Function MyMethod(ByVal a As String, ByVal b As Integer) As String
Return("Output from MyMethod, which takes two parameters, one as String and second as
Integer")
End Function
Public Overloads Function MyMethod(ByVal s As String, ByVal c As String) As String
Return("Output from MyMethod, which takes two String type parameters")
End Function
End Class 'My_Class
Run Code By
pressing 'F5'
Paste code after the
'End' of '_Default' class
Dim mc1 As New My_Class
Label1.Text = mc1.MyMethod()
Label2.Text = mc1.MyMethod("abc", 10)
Label3.Text = mc1.MyMethod("xyz", "lmn")
8
OverloadingVB - Output
Output on browser after pressing the button.
9
Partial Class _Default Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim mc1 As New My_Class
Label1.Text = mc1.MyMethod()
Label2.Text = mc1.MyMethod("abc", 10)
Label3.Text = mc1.MyMethod("xyz", "lmn")
End Sub
End Class
Class My_Class
Public Overloads Function MyMethod() As String
Return ("Output from MyMethod, which takes no parameter")
End Function
Public Overloads Function MyMethod(ByVal a As String, ByVal b As Integer) As String
Return ("Output from MyMethod, which takes two parameters, one as String
and second as Integer")
End Function
Public Overloads Function MyMethod(ByVal s As String, ByVal c As String) As String
Return ("Output from MyMethod, which takes two String types parameters")
End Function
End Class 'My_Class
OverloadingVB – Example Explanation - 1
This is 'My_Class' class, which has
multiple 'MyMethod' methods.
This statement creates the object 'mc1' of
'My_Class' class.
10
Partial Class _Default Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim mc1 As New My_Class
Label1.Text = mc1.MyMethod()
Label2.Text = mc1.MyMethod("abc", 10)
Label3.Text = mc1.MyMethod("xyz", "lmn")
End Sub
End Class
Class My_Class
Public Overloads Function MyMethod() As String
Return ("Output from MyMethod, which takes no parameter")
End Function
Public Overloads Function MyMethod(ByVal a As String, ByVal b As Integer) As String
Return ("Output from MyMethod, which takes two parameters, one as String
and second as Integer")
End Function
Public Overloads Function MyMethod(ByVal s As String, ByVal c As String) As String
Return ("Output from MyMethod, which takes two String types parameters")
End Function
End Class 'My_Class
OverloadingVB – Example Explanation - 2
This statement call the method
'MyMethod()' of 'My_Class' without
passing any 'parameter' to it
When we call the method 'MyMethod'
without passing any parameter
Then this method will invoke.
Similarly other 'MyMethod'
Functions shall be invoked
based on type of parameters.
Watch the use of 'Overloads' keyword in each function.
11
OverloadingVB : Error Trials
 Try removing 'Overloads' keyword from any one method. Watch the runtime error as follows:
BC31409: function 'MyMethod' must be declared 'Overloads' because another 'MyMethod' is declared 'Overloads' or
'Overrides'.
You may also try to move the mouse over the function MyMethod (Shown with sawtooth underline) in your code editing
window. See the tooltip as follows to watch the expected error in advance as follows.
You can see that your IDE helps you to find problems in advance.
 Try defining another method in My_Class as follows and watch the runtime error.
Public Overloads Function MyMethod(ByVal str1 As String, ByVal str2 As String) As
String
Return ("Output from trial method")
End Function
BC30269: 'Public Overloads Function MyMethod(s As String, c As String) As String' has multiple definitions with identical
signatures.
You can now notice that only one function with a particular type of parameter is possible even though the parameter
names defined are different.
12
OverloadingVB : Home Exercise
 You are required to make a program where you can
declare a class 'Shape'.
 Make a public method area where the radius parameter is
passed. Within method write the formula 3.14 * r * r for area
of circle.
 Make another public method area where two sides value
parameters are passed. Within method write formula side1 *
side2 for area of a rectangle.
 Now write some event handler to show functionality of getting
the area of circle or area of a rectangle using the same method
area( ).
We have told you that overloading is on the basis of similarly named functions
but with different set of parameters.
You can try creating similar exercises for yourself to master the variations of
parameter types. Is overloading required if a method of same name is defined in
another class.
Oh! Its all too confusing, its better to go back to my other hobbies.
13
Method OverLoadingVB : Learning Summary Review
 Concept of Method Overloading
 Method overloading is one of the fundamental type of polymorphic behavior in
OOPS.
 In this case multiple methods or functions can be defined with same name but with
different number and type of parameters.
 Example of area of circle or rectangle using same method area( ):
Class Shape
Overloaded Function area(radius)
return ( 3.14 * radius * radius)
End Function
Overloaded Function area(side1,side2)
return ( side1 * side2)
End Function
End Class
(above is a demonstration code only)
 Method Overloading is not required across classes as here same naming is
already permitted due Class by itself having the encapsulation property.
14
Ask and guide me at
sunmitraeducation@gmail.com
Share this information with as
many people as possible.
Keep visiting www.sunmitra.com
for programme updates.

More Related Content

What's hot

Effective Java - Design Method Signature Overload Varargs
Effective Java - Design Method Signature Overload VarargsEffective Java - Design Method Signature Overload Varargs
Effective Java - Design Method Signature Overload VarargsRoshan Deniyage
 
Booa8 Slide 09
Booa8 Slide 09Booa8 Slide 09
Booa8 Slide 09oswchavez
 
Main method in java
Main method in javaMain method in java
Main method in javaHitesh Kumar
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsleminhvuong
 
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019iFour Technolab Pvt. Ltd.
 
Java Script Language Tutorial
Java Script Language TutorialJava Script Language Tutorial
Java Script Language Tutorialvikram singh
 
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteMVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteRavi Bhadauria
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++ppd1961
 

What's hot (15)

Effective Java - Design Method Signature Overload Varargs
Effective Java - Design Method Signature Overload VarargsEffective Java - Design Method Signature Overload Varargs
Effective Java - Design Method Signature Overload Varargs
 
Booa8 Slide 09
Booa8 Slide 09Booa8 Slide 09
Booa8 Slide 09
 
LISP: Macros in lisp
LISP: Macros in lispLISP: Macros in lisp
LISP: Macros in lisp
 
Intake 37 1
Intake 37 1Intake 37 1
Intake 37 1
 
Intake 37 5
Intake 37 5Intake 37 5
Intake 37 5
 
Fundamentals of matlab programming
Fundamentals of matlab programmingFundamentals of matlab programming
Fundamentals of matlab programming
 
Understanding Subroutines and Functions in VB6
Understanding Subroutines and Functions in VB6Understanding Subroutines and Functions in VB6
Understanding Subroutines and Functions in VB6
 
Main method in java
Main method in javaMain method in java
Main method in java
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019
 
Java Script Language Tutorial
Java Script Language TutorialJava Script Language Tutorial
Java Script Language Tutorial
 
Books
BooksBooks
Books
 
Create and analyse programs
Create and analyse programsCreate and analyse programs
Create and analyse programs
 
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteMVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
 

Similar to Progamming Primer Polymorphism (Method Overloading) VB

CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaHamad Odhabi
 
Program by Demonstration using Version Space Algebra
Program by Demonstration using Version Space AlgebraProgram by Demonstration using Version Space Algebra
Program by Demonstration using Version Space AlgebraMaeda Hanafi
 
exercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdfexercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdfenodani2008
 
AIA101.4.Automating Access
AIA101.4.Automating AccessAIA101.4.Automating Access
AIA101.4.Automating AccessDan D'Urso
 
Logistic Regression using Mahout
Logistic Regression using MahoutLogistic Regression using Mahout
Logistic Regression using Mahouttanuvir
 
Unit iii vb_study_materials
Unit iii vb_study_materialsUnit iii vb_study_materials
Unit iii vb_study_materialsgayaramesh
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Akhil Mittal
 
Chap2 class,objects
Chap2 class,objectsChap2 class,objects
Chap2 class,objectsraksharao
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C ProgrammingShuvongkor Barman
 
Polymorphism in java
Polymorphism in java Polymorphism in java
Polymorphism in java Janu Jahnavi
 
SAS Macros part 3
SAS Macros part 3SAS Macros part 3
SAS Macros part 3venkatam
 

Similar to Progamming Primer Polymorphism (Method Overloading) VB (20)

Vb.net iv
Vb.net ivVb.net iv
Vb.net iv
 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in Java
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Program by Demonstration using Version Space Algebra
Program by Demonstration using Version Space AlgebraProgram by Demonstration using Version Space Algebra
Program by Demonstration using Version Space Algebra
 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
 
exercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdfexercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdf
 
AIA101.4.Automating Access
AIA101.4.Automating AccessAIA101.4.Automating Access
AIA101.4.Automating Access
 
Logistic Regression using Mahout
Logistic Regression using MahoutLogistic Regression using Mahout
Logistic Regression using Mahout
 
Unit iii vb_study_materials
Unit iii vb_study_materialsUnit iii vb_study_materials
Unit iii vb_study_materials
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
 
Chap2 class,objects
Chap2 class,objectsChap2 class,objects
Chap2 class,objects
 
Advanced oops concept using asp
Advanced oops concept using aspAdvanced oops concept using asp
Advanced oops concept using asp
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
06 procedures
06 procedures06 procedures
06 procedures
 
Maxbox starter
Maxbox starterMaxbox starter
Maxbox starter
 
Polymorphism in java
Polymorphism in java Polymorphism in java
Polymorphism in java
 
Java execise
Java execiseJava execise
Java execise
 
SAS Macros part 3
SAS Macros part 3SAS Macros part 3
SAS Macros part 3
 
Vb (1)
Vb (1)Vb (1)
Vb (1)
 
Refactoring Chapter11
Refactoring Chapter11Refactoring Chapter11
Refactoring Chapter11
 

More from sunmitraeducation

More from sunmitraeducation (20)

Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
Installing JDK and first java program
Installing JDK and first java programInstalling JDK and first java program
Installing JDK and first java program
 
Project1 VB
Project1 VBProject1 VB
Project1 VB
 
Project1 CS
Project1 CSProject1 CS
Project1 CS
 
Grid Vew Control VB
Grid Vew Control VBGrid Vew Control VB
Grid Vew Control VB
 
Grid View Control CS
Grid View Control CSGrid View Control CS
Grid View Control CS
 
Ms Access
Ms AccessMs Access
Ms Access
 
Database Basics Theory
Database Basics TheoryDatabase Basics Theory
Database Basics Theory
 
Visual Web Developer and Web Controls VB set 3
Visual Web Developer and Web Controls VB set 3Visual Web Developer and Web Controls VB set 3
Visual Web Developer and Web Controls VB set 3
 
Visual Web Developer and Web Controls CS set 3
Visual Web Developer and Web Controls CS set 3Visual Web Developer and Web Controls CS set 3
Visual Web Developer and Web Controls CS set 3
 
Programming Primer EncapsulationVB
Programming Primer EncapsulationVBProgramming Primer EncapsulationVB
Programming Primer EncapsulationVB
 
Programming Primer Encapsulation CS
Programming Primer Encapsulation CSProgramming Primer Encapsulation CS
Programming Primer Encapsulation CS
 
Programming Primer Inheritance VB
Programming Primer Inheritance VBProgramming Primer Inheritance VB
Programming Primer Inheritance VB
 
Programming Primer Inheritance CS
Programming Primer Inheritance CSProgramming Primer Inheritance CS
Programming Primer Inheritance CS
 
ProgrammingPrimerAndOOPS
ProgrammingPrimerAndOOPSProgrammingPrimerAndOOPS
ProgrammingPrimerAndOOPS
 
Web Server Controls VB Set 1
Web Server Controls VB Set 1Web Server Controls VB Set 1
Web Server Controls VB Set 1
 
Web Server Controls CS Set
Web Server Controls CS Set Web Server Controls CS Set
Web Server Controls CS Set
 
Web Controls Set-1
Web Controls Set-1Web Controls Set-1
Web Controls Set-1
 
Understanding IDEs
Understanding IDEsUnderstanding IDEs
Understanding IDEs
 
Html Server Image Control VB
Html Server Image Control VBHtml Server Image Control VB
Html Server Image Control VB
 

Recently uploaded

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 

Progamming Primer Polymorphism (Method Overloading) VB

  • 1. 1 A Programme Under the Compumitra Series Programming Primer – Polymorphism (Method Overloading) LAB WORK GUIDE
  • 2. 2 OUTLINE Polymorphism  Method Overloading (using VB) Example Template Creation. Code Creation. Output Evaluation. Example Explanation. Error Trials. Home Exercise. Review Summary.
  • 3. 3 Polymorphism (Method Overloading) Using VB Method overloading is a one of the techniques of creating multiple polymorphic classes with variation in its number and type of parameters. For e.g. MyMethod(param1) and MyMethod(param1, param2) are two overloaded methods of same name but they act differently on the basis of parameters.
  • 4. 4 OverloadingVB– Creating Button and Label Template Button with 'Text' Property set to 'Method Overloading'. Three Labels to hold the place for output display with 'text' property set to NULL (blank). • Follow Standard Website Creation Steps and set your path to C:Learner<student-id>ProgrammingPrimerOverloadingVB • Now Create the Execution Event Handler as a button and output place holders as follows.
  • 5. 5 OverloadingVB – Copy/Paste Code-1 Dim mc1 As New My_Class Label1.Text = mc1.MyMethod() Label2.Text = mc1.MyMethod("abc", 10) Label3.Text = mc1.MyMethod("xyz", "lmn") Go to 'Default.aspx.vb' by double clicking on 'Button' ('Method Overloading' button) of 'Default.aspx' and 'Paste' the Code in 'Button1_Click' method Dim mc1 As New My_Class Label1.Text = mc1.MyMethod() Label2.Text = mc1.MyMethod("abc", 10) Label3.Text = mc1.MyMethod("xyz", "lmn") Copy this Code
  • 6. 6 OverloadingVB - Copy Code-2 Class My_Class Public Overloads Function MyMethod() As String Return("Output from MyMethod, which takes no parameter") End Function Public Overloads Function MyMethod(ByVal a As String, ByVal b As Integer) As String Return("Output from MyMethod, which takes two parameters, one as String and second as Integer") End Function Public Overloads Function MyMethod(ByVal s As String, ByVal c As String) As String Return("Output from MyMethod, which takes two String type parameters") End Function End Class 'My_Class Copy this Code
  • 7. 7 OverloadingVB - Paste Code-2 Class My_Class Public Overloads Function MyMethod() As String Return("Output from MyMethod, which takes no parameter") End Function Public Overloads Function MyMethod(ByVal a As String, ByVal b As Integer) As String Return("Output from MyMethod, which takes two parameters, one as String and second as Integer") End Function Public Overloads Function MyMethod(ByVal s As String, ByVal c As String) As String Return("Output from MyMethod, which takes two String type parameters") End Function End Class 'My_Class Run Code By pressing 'F5' Paste code after the 'End' of '_Default' class Dim mc1 As New My_Class Label1.Text = mc1.MyMethod() Label2.Text = mc1.MyMethod("abc", 10) Label3.Text = mc1.MyMethod("xyz", "lmn")
  • 8. 8 OverloadingVB - Output Output on browser after pressing the button.
  • 9. 9 Partial Class _Default Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim mc1 As New My_Class Label1.Text = mc1.MyMethod() Label2.Text = mc1.MyMethod("abc", 10) Label3.Text = mc1.MyMethod("xyz", "lmn") End Sub End Class Class My_Class Public Overloads Function MyMethod() As String Return ("Output from MyMethod, which takes no parameter") End Function Public Overloads Function MyMethod(ByVal a As String, ByVal b As Integer) As String Return ("Output from MyMethod, which takes two parameters, one as String and second as Integer") End Function Public Overloads Function MyMethod(ByVal s As String, ByVal c As String) As String Return ("Output from MyMethod, which takes two String types parameters") End Function End Class 'My_Class OverloadingVB – Example Explanation - 1 This is 'My_Class' class, which has multiple 'MyMethod' methods. This statement creates the object 'mc1' of 'My_Class' class.
  • 10. 10 Partial Class _Default Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim mc1 As New My_Class Label1.Text = mc1.MyMethod() Label2.Text = mc1.MyMethod("abc", 10) Label3.Text = mc1.MyMethod("xyz", "lmn") End Sub End Class Class My_Class Public Overloads Function MyMethod() As String Return ("Output from MyMethod, which takes no parameter") End Function Public Overloads Function MyMethod(ByVal a As String, ByVal b As Integer) As String Return ("Output from MyMethod, which takes two parameters, one as String and second as Integer") End Function Public Overloads Function MyMethod(ByVal s As String, ByVal c As String) As String Return ("Output from MyMethod, which takes two String types parameters") End Function End Class 'My_Class OverloadingVB – Example Explanation - 2 This statement call the method 'MyMethod()' of 'My_Class' without passing any 'parameter' to it When we call the method 'MyMethod' without passing any parameter Then this method will invoke. Similarly other 'MyMethod' Functions shall be invoked based on type of parameters. Watch the use of 'Overloads' keyword in each function.
  • 11. 11 OverloadingVB : Error Trials  Try removing 'Overloads' keyword from any one method. Watch the runtime error as follows: BC31409: function 'MyMethod' must be declared 'Overloads' because another 'MyMethod' is declared 'Overloads' or 'Overrides'. You may also try to move the mouse over the function MyMethod (Shown with sawtooth underline) in your code editing window. See the tooltip as follows to watch the expected error in advance as follows. You can see that your IDE helps you to find problems in advance.  Try defining another method in My_Class as follows and watch the runtime error. Public Overloads Function MyMethod(ByVal str1 As String, ByVal str2 As String) As String Return ("Output from trial method") End Function BC30269: 'Public Overloads Function MyMethod(s As String, c As String) As String' has multiple definitions with identical signatures. You can now notice that only one function with a particular type of parameter is possible even though the parameter names defined are different.
  • 12. 12 OverloadingVB : Home Exercise  You are required to make a program where you can declare a class 'Shape'.  Make a public method area where the radius parameter is passed. Within method write the formula 3.14 * r * r for area of circle.  Make another public method area where two sides value parameters are passed. Within method write formula side1 * side2 for area of a rectangle.  Now write some event handler to show functionality of getting the area of circle or area of a rectangle using the same method area( ). We have told you that overloading is on the basis of similarly named functions but with different set of parameters. You can try creating similar exercises for yourself to master the variations of parameter types. Is overloading required if a method of same name is defined in another class. Oh! Its all too confusing, its better to go back to my other hobbies.
  • 13. 13 Method OverLoadingVB : Learning Summary Review  Concept of Method Overloading  Method overloading is one of the fundamental type of polymorphic behavior in OOPS.  In this case multiple methods or functions can be defined with same name but with different number and type of parameters.  Example of area of circle or rectangle using same method area( ): Class Shape Overloaded Function area(radius) return ( 3.14 * radius * radius) End Function Overloaded Function area(side1,side2) return ( side1 * side2) End Function End Class (above is a demonstration code only)  Method Overloading is not required across classes as here same naming is already permitted due Class by itself having the encapsulation property.
  • 14. 14 Ask and guide me at sunmitraeducation@gmail.com Share this information with as many people as possible. Keep visiting www.sunmitra.com for programme updates.