Skip to content

Commit

Permalink
demo: example of method overloading/ static polymorphism
Browse files Browse the repository at this point in the history
  • Loading branch information
NirmalSilwal committed Sep 3, 2020
1 parent 4e7e45d commit 6bd1aa5
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions CodingBlocks Training/Day16/methodOverloading.java
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);
}
}

0 comments on commit 6bd1aa5

Please sign in to comment.