SlideShare a Scribd company logo
Presented By
Name- Sonya Akter Rupa
ID- 315161009
Batch- 8th
Semester- 5th
Department of CSE
Email- sonyarupa321@gmail.com
Hamdard University
Bangladesh
Thursday, August 3, 2017 Prepered By Sonya Akter Rupa
Presentation on
Method Overloading in Java
Outline
What is signature?
What is Polymorphism?
What is Method?
Method Overloading
Why overload a method?
Example of Method Overloading
Reference Books & Websites
Thursday, August 3, 2017 Prepered By Sonya Akter Rupa 2
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!
Thursday, August 3, 2017 Prepered By Sonya Akter Rupa 3
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
Thursday, August 3, 2017 Prepered By Sonya Akter Rupa 4
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.
Thursday, August 3, 2017 Prepered By Sonya Akter Rupa 5
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.
Thursday, August 3, 2017 Prepered By Sonya Akter Rupa 6
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();
}
Thursday, August 3, 2017 Prepered By Sonya Akter Rupa 7
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
Thursday, August 3, 2017 Prepered By Sonya Akter Rupa 8
Reference Books & Websites
JAVA The Complete Reference by Herbert Schild
en.wikipedia.org/wiki/method
en.wikipedia.org/wiki/method_overloading
www.quora.com/reason-of-method-overloading
Thursday, August 3, 2017 Prepered By Sonya Akter Rupa 9
Thursday, August 3, 2017 Prepered By Sonya Akter Rupa
Ad

More Related Content

What's hot (20)

Polymorphism In c++
Polymorphism In c++Polymorphism In c++
Polymorphism In c++
Vishesh Jha
 
Applets in java
Applets in javaApplets in java
Applets in java
Wani Zahoor
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
rajveer_Pannu
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
Hitesh Kumar
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
HarshitaAshwani
 
Method overloading
Method overloadingMethod overloading
Method overloading
Azaz Maverick
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
Hitesh Kumar
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
Method overloading
Method overloadingMethod overloading
Method overloading
Lovely Professional University
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
ThamizhselviKrishnam
 
Polymorphism in java
Polymorphism in java Polymorphism in java
Polymorphism in java
Janu Jahnavi
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In Java
CharthaGaglani
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
Shraddha
 
Applets
AppletsApplets
Applets
Prabhakaran V M
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
Raja Sekhar
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
Java2Blog
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
Ahsan Raja
 
Java IO
Java IOJava IO
Java IO
UTSAB NEUPANE
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Hitesh Kumar
 
Super Keyword in Java.pptx
Super Keyword in Java.pptxSuper Keyword in Java.pptx
Super Keyword in Java.pptx
KrutikaWankhade1
 

Similar to Method Overloading in Java (20)

Method Overloading in Java
Method Overloading in JavaMethod Overloading in Java
Method Overloading in Java
Delowar Hossain
 
Oop in kotlin
Oop in kotlinOop in kotlin
Oop in kotlin
Abdul Rahman Masri Attal
 
Polymorphism (Ad-hoc and Universal)
Polymorphism (Ad-hoc and Universal)Polymorphism (Ad-hoc and Universal)
Polymorphism (Ad-hoc and Universal)
Sérgio Souza Costa
 
polymorphism method overloading and overriding .pptx
polymorphism method overloading  and overriding .pptxpolymorphism method overloading  and overriding .pptx
polymorphism method overloading and overriding .pptx
thamaraiselvangts441
 
Inheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptxInheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptx
MalligaarjunanN
 
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
 
Myanmar Named Entity Recognition with Hidden Markov Model
Myanmar Named Entity Recognition with Hidden Markov ModelMyanmar Named Entity Recognition with Hidden Markov Model
Myanmar Named Entity Recognition with Hidden Markov Model
ijtsrd
 
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
Suresh Mohta
 
Basics of oops concept
Basics of oops conceptBasics of oops concept
Basics of oops concept
DINESH KUMAR ARIVARASAN
 
Object Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. PolymorphismObject Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. Polymorphism
AndiNurkholis1
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
ilias ahmed
 
Automatic multiple choice question generation system for
Automatic multiple choice question generation system forAutomatic multiple choice question generation system for
Automatic multiple choice question generation system for
Alexander Decker
 
Clustering Algorithm for Gujarati Language
Clustering Algorithm for Gujarati LanguageClustering Algorithm for Gujarati Language
Clustering Algorithm for Gujarati Language
ijsrd.com
 
Java Extension Methods
Java Extension MethodsJava Extension Methods
Java Extension Methods
Andreas Enbohm
 
K017367680
K017367680K017367680
K017367680
IOSR Journals
 
A survey of Stemming Algorithms for Information Retrieval
A survey of Stemming Algorithms for Information RetrievalA survey of Stemming Algorithms for Information Retrieval
A survey of Stemming Algorithms for Information Retrieval
iosrjce
 
Ijartes v1-i1-002
Ijartes v1-i1-002Ijartes v1-i1-002
Ijartes v1-i1-002
IJARTES
 
A Primer on High-Quality Identifier Naming
A Primer on High-Quality Identifier NamingA Primer on High-Quality Identifier Naming
A Primer on High-Quality Identifier Naming
University of Hawai‘i at Mānoa
 
Polymorphism.pptx
Polymorphism.pptxPolymorphism.pptx
Polymorphism.pptx
RiturajJain8
 
oblect oriented programming language in java notes .pdf
oblect oriented programming language in java  notes .pdfoblect oriented programming language in java  notes .pdf
oblect oriented programming language in java notes .pdf
sanraku980
 
Method Overloading in Java
Method Overloading in JavaMethod Overloading in Java
Method Overloading in Java
Delowar Hossain
 
Polymorphism (Ad-hoc and Universal)
Polymorphism (Ad-hoc and Universal)Polymorphism (Ad-hoc and Universal)
Polymorphism (Ad-hoc and Universal)
Sérgio Souza Costa
 
polymorphism method overloading and overriding .pptx
polymorphism method overloading  and overriding .pptxpolymorphism method overloading  and overriding .pptx
polymorphism method overloading and overriding .pptx
thamaraiselvangts441
 
Inheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptxInheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptx
MalligaarjunanN
 
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
 
Myanmar Named Entity Recognition with Hidden Markov Model
Myanmar Named Entity Recognition with Hidden Markov ModelMyanmar Named Entity Recognition with Hidden Markov Model
Myanmar Named Entity Recognition with Hidden Markov Model
ijtsrd
 
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
Suresh Mohta
 
Object Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. PolymorphismObject Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. Polymorphism
AndiNurkholis1
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
ilias ahmed
 
Automatic multiple choice question generation system for
Automatic multiple choice question generation system forAutomatic multiple choice question generation system for
Automatic multiple choice question generation system for
Alexander Decker
 
Clustering Algorithm for Gujarati Language
Clustering Algorithm for Gujarati LanguageClustering Algorithm for Gujarati Language
Clustering Algorithm for Gujarati Language
ijsrd.com
 
Java Extension Methods
Java Extension MethodsJava Extension Methods
Java Extension Methods
Andreas Enbohm
 
A survey of Stemming Algorithms for Information Retrieval
A survey of Stemming Algorithms for Information RetrievalA survey of Stemming Algorithms for Information Retrieval
A survey of Stemming Algorithms for Information Retrieval
iosrjce
 
Ijartes v1-i1-002
Ijartes v1-i1-002Ijartes v1-i1-002
Ijartes v1-i1-002
IJARTES
 
oblect oriented programming language in java notes .pdf
oblect oriented programming language in java  notes .pdfoblect oriented programming language in java  notes .pdf
oblect oriented programming language in java notes .pdf
sanraku980
 
Ad

More from Sonya Akter Rupa (9)

Synchronous Counter in Digital Logic Device
Synchronous Counter in Digital Logic DeviceSynchronous Counter in Digital Logic Device
Synchronous Counter in Digital Logic Device
Sonya Akter Rupa
 
Enviremental Pollution
Enviremental PollutionEnviremental Pollution
Enviremental Pollution
Sonya Akter Rupa
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
Sonya Akter Rupa
 
File in C Programming
File in C ProgrammingFile in C Programming
File in C Programming
Sonya Akter Rupa
 
Pointer in C
Pointer in CPointer in C
Pointer in C
Sonya Akter Rupa
 
One Dimentional Array
One Dimentional ArrayOne Dimentional Array
One Dimentional Array
Sonya Akter Rupa
 
Two Dimentional Array
Two Dimentional ArrayTwo Dimentional Array
Two Dimentional Array
Sonya Akter Rupa
 
The population is resource or burden for Bangladesh
The population is resource or burden for BangladeshThe population is resource or burden for Bangladesh
The population is resource or burden for Bangladesh
Sonya Akter Rupa
 
Spherical Polar Coordinate System- physics II
Spherical Polar Coordinate System- physics IISpherical Polar Coordinate System- physics II
Spherical Polar Coordinate System- physics II
Sonya Akter Rupa
 
Synchronous Counter in Digital Logic Device
Synchronous Counter in Digital Logic DeviceSynchronous Counter in Digital Logic Device
Synchronous Counter in Digital Logic Device
Sonya Akter Rupa
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
Sonya Akter Rupa
 
The population is resource or burden for Bangladesh
The population is resource or burden for BangladeshThe population is resource or burden for Bangladesh
The population is resource or burden for Bangladesh
Sonya Akter Rupa
 
Spherical Polar Coordinate System- physics II
Spherical Polar Coordinate System- physics IISpherical Polar Coordinate System- physics II
Spherical Polar Coordinate System- physics II
Sonya Akter Rupa
 
Ad

Recently uploaded (20)

ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdfML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
rameshwarchintamani
 
Evonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdfEvonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdf
szhang13
 
Working with USDOT UTCs: From Conception to Implementation
Working with USDOT UTCs: From Conception to ImplementationWorking with USDOT UTCs: From Conception to Implementation
Working with USDOT UTCs: From Conception to Implementation
Alabama Transportation Assistance Program
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
Modeling the Influence of Environmental Factors on Concrete Evaporation Rate
Modeling the Influence of Environmental Factors on Concrete Evaporation RateModeling the Influence of Environmental Factors on Concrete Evaporation Rate
Modeling the Influence of Environmental Factors on Concrete Evaporation Rate
Journal of Soft Computing in Civil Engineering
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Journal of Soft Computing in Civil Engineering
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning ModelsMode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Journal of Soft Computing in Civil Engineering
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
Applications of Centroid in Structural Engineering
Applications of Centroid in Structural EngineeringApplications of Centroid in Structural Engineering
Applications of Centroid in Structural Engineering
suvrojyotihalder2006
 
Lecture - 7 Canals of the topic of the civil engineering
Lecture - 7  Canals of the topic of the civil engineeringLecture - 7  Canals of the topic of the civil engineering
Lecture - 7 Canals of the topic of the civil engineering
MJawadkhan1
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Journal of Soft Computing in Civil Engineering
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdfML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
rameshwarchintamani
 
Evonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdfEvonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdf
szhang13
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
Applications of Centroid in Structural Engineering
Applications of Centroid in Structural EngineeringApplications of Centroid in Structural Engineering
Applications of Centroid in Structural Engineering
suvrojyotihalder2006
 
Lecture - 7 Canals of the topic of the civil engineering
Lecture - 7  Canals of the topic of the civil engineeringLecture - 7  Canals of the topic of the civil engineering
Lecture - 7 Canals of the topic of the civil engineering
MJawadkhan1
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 

Method Overloading in Java

  • 1. Presented By Name- Sonya Akter Rupa ID- 315161009 Batch- 8th Semester- 5th Department of CSE Email- sonyarupa321@gmail.com Hamdard University Bangladesh Thursday, August 3, 2017 Prepered By Sonya Akter Rupa Presentation on Method Overloading in Java
  • 2. Outline What is signature? What is Polymorphism? What is Method? Method Overloading Why overload a method? Example of Method Overloading Reference Books & Websites Thursday, August 3, 2017 Prepered By Sonya Akter Rupa 2
  • 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! Thursday, August 3, 2017 Prepered By Sonya Akter Rupa 3
  • 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 Thursday, August 3, 2017 Prepered By Sonya Akter Rupa 4
  • 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. Thursday, August 3, 2017 Prepered By Sonya Akter Rupa 5
  • 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. Thursday, August 3, 2017 Prepered By Sonya Akter Rupa 6
  • 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(); } Thursday, August 3, 2017 Prepered By Sonya Akter Rupa 7
  • 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 Thursday, August 3, 2017 Prepered By Sonya Akter Rupa 8
  • 9. Reference Books & Websites JAVA The Complete Reference by Herbert Schild en.wikipedia.org/wiki/method en.wikipedia.org/wiki/method_overloading www.quora.com/reason-of-method-overloading Thursday, August 3, 2017 Prepered By Sonya Akter Rupa 9
  • 10. Thursday, August 3, 2017 Prepered By Sonya Akter Rupa
  翻译: