From this slide you can know about
- Signature
- Polymorphism
-Method
-Types of Method
- Method Overloading
- Sample programme
- Reference Books & websites name
I hope, it is beneficial for beginner Java learner. It's just a simple overview of the topic Method Overloading in Java.
complete construction, environmental and economics information of biomass com...
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