SlideShare a Scribd company logo
1 of 10
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

More Related Content

What's hot

Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
backdoor
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
Abhilash Nair
 

What's hot (20)

Method overriding
Method overridingMethod overriding
Method overriding
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Delegates and events in C#
Delegates and events in C#Delegates and events in C#
Delegates and events in C#
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Java- Nested Classes
Java- Nested ClassesJava- Nested Classes
Java- Nested Classes
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and Interface
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
Java interface
Java interfaceJava interface
Java interface
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In Java
 

Similar to Method Overloading in Java

Similar to Method Overloading in Java (20)

Method Overloading in Java
Method Overloading in JavaMethod Overloading in Java
Method Overloading in Java
 
Oop in kotlin
Oop in kotlinOop in kotlin
Oop in kotlin
 
Polymorphism (Ad-hoc and Universal)
Polymorphism (Ad-hoc and Universal)Polymorphism (Ad-hoc and Universal)
Polymorphism (Ad-hoc and Universal)
 
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
 
Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)
 
Polymorphism in java
Polymorphism in java Polymorphism in java
Polymorphism in java
 
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
 
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
 
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
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
 
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
 
Clustering Algorithm for Gujarati Language
Clustering Algorithm for Gujarati LanguageClustering Algorithm for Gujarati Language
Clustering Algorithm for Gujarati Language
 
Java Extension Methods
Java Extension MethodsJava Extension Methods
Java Extension Methods
 
K017367680
K017367680K017367680
K017367680
 
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
 
Ijartes v1-i1-002
Ijartes v1-i1-002Ijartes v1-i1-002
Ijartes v1-i1-002
 
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
 
Polymorphism.pptx
Polymorphism.pptxPolymorphism.pptx
Polymorphism.pptx
 

More from Sonya Akter Rupa

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
 
Enviremental Pollution
Enviremental PollutionEnviremental Pollution
Enviremental Pollution
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
 
File in C Programming
File in C ProgrammingFile in C Programming
File in C Programming
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
One Dimentional Array
One Dimentional ArrayOne Dimentional Array
One Dimentional Array
 
Two Dimentional Array
Two Dimentional ArrayTwo Dimentional Array
Two Dimentional Array
 
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
 
Spherical Polar Coordinate System- physics II
Spherical Polar Coordinate System- physics IISpherical Polar Coordinate System- physics II
Spherical Polar Coordinate System- physics II
 

Recently uploaded

Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 

Recently uploaded (20)

KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 

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