-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
demo: example of method overloading/ static polymorphism
- Loading branch information
1 parent
4e7e45d
commit 6bd1aa5
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package Lecture16; | ||
|
||
public class methodOverloading { | ||
|
||
public static void main(String[] args) { | ||
|
||
add(1, 2); // 3 | ||
add("100", "200"); // 100200 | ||
add(50); // 50 | ||
add(20, "c"); // 20c | ||
add("a", 30); // a30 | ||
|
||
} | ||
|
||
public static void add(int a, int b) { | ||
System.out.println(a + b); | ||
} | ||
|
||
public static void add(String a, String b) { | ||
System.out.println(a + b); | ||
} | ||
|
||
public static void add(int a) { | ||
System.out.println(a); | ||
} | ||
|
||
public static void add(int a, String b) { | ||
System.out.println(a + b); | ||
} | ||
|
||
public static void add(String a, int b){ | ||
System.out.println(a + b); | ||
} | ||
} |