-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMethodOverloadingExample.java
More file actions
36 lines (26 loc) · 1010 Bytes
/
MethodOverloadingExample.java
File metadata and controls
36 lines (26 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.javaexperiments;
public class MethodOverloadingExample {
/**
* Method Overloading is basically same method name but with different method signature
*/
public static void main(String[] args) {
int rating = calculateScore("Bruce Wayne", 300);
System.out.println("The player 1 rating is " + rating);
int ratingUnnamed = calculateScore(500);
System.out.println("The player 2 rating is " + ratingUnnamed);
int ratingZero = calculateScore();
System.out.println("The player 3 rating is " + ratingZero);
}
public static int calculateScore(String name, int score) {
System.out.println("Player " + name + " scored " + score);
return score * 1000;
}
public static int calculateScore(int score) {
System.out.println("Unnamed player scored " + score);
return score * 1000;
}
public static int calculateScore() {
System.out.println("No score ");
return 0;
}
}