-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter13.java
More file actions
59 lines (40 loc) ยท 1.75 KB
/
Chapter13.java
File metadata and controls
59 lines (40 loc) ยท 1.75 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package javastudy;
//๋ฉ์๋ ์ค๋ฒ๋ก๋ฉ(Method Overloading)
//๋ฉ์๋ ์ด๋ฆ์ ๋์ผํ์ง๋ง ๋งค๊ฐ๋ณ์์ ์๋ฃํ์ด๋ ๊ฐ์๊ฐ ๋ค๋ฅด๋ฉด ์ฌ๋ฌ ๊ฐ์ ๋ฉ์๋๋ฅผ ๋ง๋ค์ด ๋๊ณ ์ฌ์ฉํ ์ ์๋ค
class Operator {
//๋ฉ์๋ ์ค๋ฒ๋ก๋ฉ
// 4 3
int multiply(int x, int y) {
return x * y; //๊ณฑํ ๊ฒฐ๊ณผ ๊ฐ์ ํธ์ถํ ๊ณณ์ผ๋ก ๋๋ ค์ค๋ค
}
double multiply(double x, double y) { //๋งค๊ฐ๋ณ์์ ์๋ฃํ์ด ๋ค๋ฅด๋ค
return x * y; //๊ณฑํ ๊ฒฐ๊ณผ ๊ฐ์ ํธ์ถํ ๊ณณ์ผ๋ก ๋๋ ค์ค๋ค
}
double multiply(int x, double y) {
return x * y; //๊ณฑํ ๊ฒฐ๊ณผ ๊ฐ์ ํธ์ถํ ๊ณณ์ผ๋ก ๋๋ ค์ค๋ค
}
double multiply(double x, int y) {
return x * y; //๊ณฑํ ๊ฒฐ๊ณผ ๊ฐ์ ํธ์ถํ ๊ณณ์ผ๋ก ๋๋ ค์ค๋ค
}
double multiply(double x) { //๋งค๊ฐ๋ณ์์ ๊ฐ์๊ฐ ๋ค๋ฅด๋ค
return x * x; //๊ณฑํ ๊ฒฐ๊ณผ ๊ฐ์ ํธ์ถํ ๊ณณ์ผ๋ก ๋๋ ค์ค๋ค
}
}
public class Chapter13 {
public static void main(String[] args) {
Operator op = new Operator();
//int multiply(int x, int y) ํธ์ถ
op.multiply(4, 3); //๋ฉ์๋ ํธ์ถ๋ ํ๊ณ ํจ์ ๋ด์์ ๋ฐํํ ๊ฐ๋ ๊ฐ์ง๊ณ ์๋ค
int result1 = op.multiply(4, 3);
System.out.println("result1 = " + result1);
System.out.println("op.multiply(4, 3) = " + op.multiply(4, 3)); //ํธ์ถ, ๊ฒฐ๊ณผ ๊ฐ์ ๊ฐ์ง๊ณ ์์
System.out.println("-------------------");
//double multiply(double x, double y) ํธ์ถ
double result2 = op.multiply(4.5, 3.5);
System.out.println("result2 = " + result2);
System.out.println("op.multiply(4.5, 3.5) = " + op.multiply(4.5, 3.5));
System.out.println("-------------------");
System.out.println(1);
System.out.println(5.5);
}
}