SlideShare a Scribd company logo
1 of 9
Pundra University of Science &
Technology
Presentation on
Method Overloading in Java
Submitted by
Name: Md.Delowar
Hossain Dolon
ID: 00817206031
Batch: 2nd
Semester: 5th
Department of CSE
Submitted to
Name: Syed Mir
Talha Zobaed
Designation: Lecturer
in CSE
Department of CSE
Outline
 What is signature?
 What is Polymorphism?
 What is Method?
Method Overloading
 Why overload a method?
Example of Method Overloading
• .
What is signature?
In any programming language, a signature is
what distinguishes one function or method
from another
In C, every function has to have a different
name
 In Java, two methods have to differ in their
names or in the number or types of their
parameters
 Same name(int i) and (int i, int j) are different
 Same name(int i) and (int k) are the same
 Same name(int i, double d) and (double d, int i) are
different
In C++, the signature also includes the
return type
But not in Java!
What is Polymorphism?
 Polymorphism means many (poly) shapes
(morph)
 In Java, polymorphism refers to the fact that
we can multiple methods with the same name
in the same class
 There are two kinds of polymorphism:
i. Overloading
◦ Two or more methods with different signatures
ii. Overriding ◦
Replacing an inherited method with another having the same
signature
What is Method?
 A Java method is a collection of
statements that are grouped together to
perform an operation.
 A class can contain any number of
methods.
 Methods can be with parameter and
without parameter.
 The parameter in a method are called
type signature.
Method Overloading
 Two or more methods within the same class
that share the same name, but with different
parameter declarations (type signatures).
 The process is referred to as method
overloading.
 Overloaded methods may have different return
types.
 When java encounters a call to an overloaded
method, it simply executes the version of the
method whose parameters match the
arguments used in the call.
Why overload a method?
 So we can use the same names for methods that do essentially the
same thing
 Example: println(int), println(double), println(boolean), println(String), etc.
 So we can supply defaults for the parameters:
int increment(int amount) {
count = count + amount;
return count;
}
int increment() {
return increment(1);
}
 Notice that one method can call another of the same name
 So we can supply additional information:
void printResults() {
System.out.println("total = " + total + ", average = " + average);
}
void printResult(String message) {
System.out.println(message + ": ");
printResults();
}
Example
class Test
{
public static void main(String args[]) {
myPrint(5);
myPrint(5.0);
}
static void myPrint(int i) {
System.out.println("int i = " + i);
}
static void myPrint(double d) { // same name, different parameters
System.out.println("double d = " + d);
}
}
int i = 5
double d = 5.0
.

More Related Content

What's hot

Chapter8:Understanding Polymorphism
Chapter8:Understanding PolymorphismChapter8:Understanding Polymorphism
Chapter8:Understanding PolymorphismIt Academy
 
Polymorphism
PolymorphismPolymorphism
PolymorphismKumar
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS ConceptBoopathi K
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented PrinciplesSujit Majety
 
A Brief Introduction to Type Constraints
A Brief Introduction to Type ConstraintsA Brief Introduction to Type Constraints
A Brief Introduction to Type ConstraintsRaffi Khatchadourian
 
DETERMINING CUSTOMER SATISFACTION IN-ECOMMERCE
DETERMINING CUSTOMER SATISFACTION IN-ECOMMERCEDETERMINING CUSTOMER SATISFACTION IN-ECOMMERCE
DETERMINING CUSTOMER SATISFACTION IN-ECOMMERCEAbdurrahimDerric
 
OOPs Difference FAQs
OOPs Difference FAQsOOPs Difference FAQs
OOPs Difference FAQsUmar Ali
 
Vi INFOTECH php-syllabus
Vi INFOTECH php-syllabusVi INFOTECH php-syllabus
Vi INFOTECH php-syllabusViINFOTECH
 
What is java polymorphism and its types in java training?
What is  java polymorphism and its types in java training?What is  java polymorphism and its types in java training?
What is java polymorphism and its types in java training?kritikumar16
 
1207028 634528828886611250
1207028 6345288288866112501207028 634528828886611250
1207028 634528828886611250Akhil Nama
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in javaAhsan Raja
 
Programming construction tools
Programming construction toolsProgramming construction tools
Programming construction toolssunilchute1
 
OOP in C#
OOP in C#OOP in C#
OOP in C#DevMix
 

What's hot (20)

Javapolymorphism
JavapolymorphismJavapolymorphism
Javapolymorphism
 
Chapter8:Understanding Polymorphism
Chapter8:Understanding PolymorphismChapter8:Understanding Polymorphism
Chapter8:Understanding Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented Principles
 
A Brief Introduction to Type Constraints
A Brief Introduction to Type ConstraintsA Brief Introduction to Type Constraints
A Brief Introduction to Type Constraints
 
DETERMINING CUSTOMER SATISFACTION IN-ECOMMERCE
DETERMINING CUSTOMER SATISFACTION IN-ECOMMERCEDETERMINING CUSTOMER SATISFACTION IN-ECOMMERCE
DETERMINING CUSTOMER SATISFACTION IN-ECOMMERCE
 
OOPs Difference FAQs
OOPs Difference FAQsOOPs Difference FAQs
OOPs Difference FAQs
 
Vi INFOTECH php-syllabus
Vi INFOTECH php-syllabusVi INFOTECH php-syllabus
Vi INFOTECH php-syllabus
 
What is java polymorphism and its types in java training?
What is  java polymorphism and its types in java training?What is  java polymorphism and its types in java training?
What is java polymorphism and its types in java training?
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
1207028 634528828886611250
1207028 6345288288866112501207028 634528828886611250
1207028 634528828886611250
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
 
Structure and Enum in c#
Structure and Enum in c#Structure and Enum in c#
Structure and Enum in c#
 
Programming construction tools
Programming construction toolsProgramming construction tools
Programming construction tools
 
OOP in C#
OOP in C#OOP in C#
OOP in C#
 
Interfaces
InterfacesInterfaces
Interfaces
 
C Omega
C OmegaC Omega
C Omega
 
Unusual C# - OOP
Unusual C# - OOPUnusual C# - OOP
Unusual C# - OOP
 

Similar to Method Overloading in Java

Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Geekster
 
Polymorphism in java
Polymorphism in java Polymorphism in java
Polymorphism in java Janu Jahnavi
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentSuresh Mohta
 
polymorphism method overloading and overriding .pptx
polymorphism method overloading  and overriding .pptxpolymorphism method overloading  and overriding .pptx
polymorphism method overloading and overriding .pptxthamaraiselvangts441
 
Inheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptxInheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptxMalligaarjunanN
 
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
 
Function overloading
Function overloadingFunction overloading
Function overloadingzindadili
 
Object Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. PolymorphismObject Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. PolymorphismAndiNurkholis1
 
java Method Overloading
java Method Overloadingjava Method Overloading
java Method Overloadingomkar bhagat
 
Overloading and overriding in vb.net
Overloading and overriding in vb.netOverloading and overriding in vb.net
Overloading and overriding in vb.netsuraj pandey
 
Introduction to method overloading & method overriding in java hdm
Introduction to method overloading & method overriding  in java  hdmIntroduction to method overloading & method overriding  in java  hdm
Introduction to method overloading & method overriding in java hdmHarshal Misalkar
 
Polymorphism in Java by Animesh Sarkar
Polymorphism in Java by Animesh SarkarPolymorphism in Java by Animesh Sarkar
Polymorphism in Java by Animesh SarkarAnimesh Sarkar
 
Learn java lessons_online
Learn java lessons_onlineLearn java lessons_online
Learn java lessons_onlinenishajj
 
Java Foundations: Methods
Java Foundations: MethodsJava Foundations: Methods
Java Foundations: MethodsSvetlin Nakov
 

Similar to Method Overloading in Java (20)

Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)
 
Oop in kotlin
Oop in kotlinOop in kotlin
Oop in kotlin
 
Polymorphism in java
Polymorphism in java Polymorphism in java
Polymorphism in java
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
 
polymorphism method overloading and overriding .pptx
polymorphism method overloading  and overriding .pptxpolymorphism method overloading  and overriding .pptx
polymorphism method overloading and overriding .pptx
 
Inheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptxInheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptx
 
Polymorphism.pptx
Polymorphism.pptxPolymorphism.pptx
Polymorphism.pptx
 
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...
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Basics of oops concept
Basics of oops conceptBasics of oops concept
Basics of oops concept
 
Object Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. PolymorphismObject Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. Polymorphism
 
java Method Overloading
java Method Overloadingjava Method Overloading
java Method Overloading
 
Overloading and overriding in vb.net
Overloading and overriding in vb.netOverloading and overriding in vb.net
Overloading and overriding in vb.net
 
Introduction to method overloading & method overriding in java hdm
Introduction to method overloading & method overriding  in java  hdmIntroduction to method overloading & method overriding  in java  hdm
Introduction to method overloading & method overriding in java hdm
 
Polymorphism in Java by Animesh Sarkar
Polymorphism in Java by Animesh SarkarPolymorphism in Java by Animesh Sarkar
Polymorphism in Java by Animesh Sarkar
 
Overloading vs Overriding.pptx
Overloading vs Overriding.pptxOverloading vs Overriding.pptx
Overloading vs Overriding.pptx
 
Learn java lessons_online
Learn java lessons_onlineLearn java lessons_online
Learn java lessons_online
 
Java Foundations: Methods
Java Foundations: MethodsJava Foundations: Methods
Java Foundations: Methods
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
Java Basics
Java BasicsJava Basics
Java Basics
 

More from Delowar Hossain

Major Function of i/o module
Major Function of i/o moduleMajor Function of i/o module
Major Function of i/o moduleDelowar Hossain
 
Different type of buses
Different type of buses Different type of buses
Different type of buses Delowar Hossain
 
Dijsktra’s Sortest path algorithm
Dijsktra’s Sortest path algorithmDijsktra’s Sortest path algorithm
Dijsktra’s Sortest path algorithmDelowar Hossain
 
Number Systems and Binary Aritmetics
Number Systems and Binary AritmeticsNumber Systems and Binary Aritmetics
Number Systems and Binary AritmeticsDelowar Hossain
 

More from Delowar Hossain (7)

Graph coloring
Graph coloringGraph coloring
Graph coloring
 
Major Function of i/o module
Major Function of i/o moduleMajor Function of i/o module
Major Function of i/o module
 
Different type of buses
Different type of buses Different type of buses
Different type of buses
 
Dijsktra’s Sortest path algorithm
Dijsktra’s Sortest path algorithmDijsktra’s Sortest path algorithm
Dijsktra’s Sortest path algorithm
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Latch and Counter
Latch and CounterLatch and Counter
Latch and Counter
 
Number Systems and Binary Aritmetics
Number Systems and Binary AritmeticsNumber Systems and Binary Aritmetics
Number Systems and Binary Aritmetics
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 

Method Overloading in Java

  • 1. Pundra University of Science & Technology Presentation on Method Overloading in Java Submitted by Name: Md.Delowar Hossain Dolon ID: 00817206031 Batch: 2nd Semester: 5th Department of CSE Submitted to Name: Syed Mir Talha Zobaed Designation: Lecturer in CSE Department of CSE
  • 2. Outline  What is signature?  What is Polymorphism?  What is Method? Method Overloading  Why overload a method? Example of Method Overloading
  • 3. • . What is signature? In any programming language, a signature is what distinguishes one function or method from another In C, every function has to have a different name  In Java, two methods have to differ in their names or in the number or types of their parameters  Same name(int i) and (int i, int j) are different  Same name(int i) and (int k) are the same  Same name(int i, double d) and (double d, int i) are different In C++, the signature also includes the return type But not in Java!
  • 4. What is Polymorphism?  Polymorphism means many (poly) shapes (morph)  In Java, polymorphism refers to the fact that we can multiple methods with the same name in the same class  There are two kinds of polymorphism: i. Overloading ◦ Two or more methods with different signatures ii. Overriding ◦ Replacing an inherited method with another having the same signature
  • 5. What is Method?  A Java method is a collection of statements that are grouped together to perform an operation.  A class can contain any number of methods.  Methods can be with parameter and without parameter.  The parameter in a method are called type signature.
  • 6. Method Overloading  Two or more methods within the same class that share the same name, but with different parameter declarations (type signatures).  The process is referred to as method overloading.  Overloaded methods may have different return types.  When java encounters a call to an overloaded method, it simply executes the version of the method whose parameters match the arguments used in the call.
  • 7. Why overload a method?  So we can use the same names for methods that do essentially the same thing  Example: println(int), println(double), println(boolean), println(String), etc.  So we can supply defaults for the parameters: int increment(int amount) { count = count + amount; return count; } int increment() { return increment(1); }  Notice that one method can call another of the same name  So we can supply additional information: void printResults() { System.out.println("total = " + total + ", average = " + average); } void printResult(String message) { System.out.println(message + ": "); printResults(); }
  • 8. Example class Test { public static void main(String args[]) { myPrint(5); myPrint(5.0); } static void myPrint(int i) { System.out.println("int i = " + i); } static void myPrint(double d) { // same name, different parameters System.out.println("double d = " + d); } } int i = 5 double d = 5.0
  • 9. .