Skip to content

Commit d57f621

Browse files
authoredJan 31, 2022
Methods Overloading
1 parent beb96ce commit d57f621

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
public class cwh_32_method_overloading {
2+
static void foo(){
3+
System.out.println("Good Morning bro!");
4+
}
5+
6+
static void foo(int a){
7+
System.out.println("Good morning " + a + " bro!");
8+
}
9+
10+
static void foo(int a, int b){
11+
System.out.println("Good morning " + a + " bro!");
12+
System.out.println("Good morning " + b + " bro!");
13+
}
14+
15+
static void foo(int a, int b, int c){
16+
System.out.println("Good morning " + a + " bro!");
17+
System.out.println("Good morning " + b + " bro!");
18+
}
19+
20+
static void change(int a){
21+
a = 98;
22+
}
23+
24+
static void change2(int [] arr){
25+
arr[0] = 98;
26+
}
27+
static void tellJoke(){
28+
System.out.println("I invented a new word!\n" +
29+
"Plagiarism!");
30+
}
31+
32+
public static void main(String[] args) {
33+
// tellJoke();
34+
35+
// Case 1: Changing the Integer
36+
//int x = 45;
37+
//change(x);
38+
//System.out.println("The value of x after running change is: " + x);
39+
40+
// Case 1: Changing the Array
41+
// int [] marks = {52, 73, 77, 89, 98, 94};
42+
// change2(marks);
43+
// System.out.println("The value of x after running change is: " + marks[0]);
44+
45+
46+
// Method Overloading
47+
foo();
48+
foo(3000);
49+
foo(3000, 4000);
50+
// Arguments are actual!
51+
52+
53+
}
54+
}

0 commit comments

Comments
 (0)
Please sign in to comment.