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
|
package quiz;
//<<<<<<<<<<<<overload method(중복함수)>>>>>>>>>>>>>>
public class Ex01_Method_OverloadMethod {
//loopLine() {"--------------------"} 7회 "---" 출력하는 함수
public static void loopLine() {
for(int i=0; i<7; i++) {
System.out.print("---\t");
}
}
//loopLine(int n) {"-------------------"} n회 "---"출력하는 함수
public static void loopLine(int n) {
for(int i=0; i<n; i++) {
System.out.print("---\t");
}
}
//loopLint(int n1, int n2) {"---------------------"} n1~n2까지 "###"출력하는 함수
public static void loopLine(int n1, int n2) {
// for(int i=n1; i<n2; i++) {
// System.out.print("###\t");
if(n1 <= 0 || n2 <=0)
return;
if(n1>n2) {
for(int i=n2; i<=n1; i++)
System.out.print("### \t");
} else {
for(int i=n1; i<=n2; i++)
System.out.print("### \t");
}
}
public static void main(String[] args) {
System.out.println("loopLine()");
loopLine();
System.out.println("loopLine(2)");
loopLine(2);
System.out.println("loopLine(5,20)");
loopLine(5, 20);
System.out.println("loopLine(0,0)");
loopLine(0,0);
System.out.println("end main");
}
}
|
cs |
-이름이 동일한 함수가 여러개 있는 경우
-함수명 같고 매개변수의 개수가 다르거나,
매개변수의 개수가 같다면 자료형이 다른 함수
'JAVA > 10_method' 카테고리의 다른 글
argument variable - 가변길이 인자 (0) | 2021.01.18 |
---|---|
static method - 객체 생성 없이 바로 사용 가능 (0) | 2021.01.18 |
instance method와 static method (0) | 2021.01.18 |
char타입 리턴 (0) | 2021.01.18 |
return자료형과 매개변수 자료형의 크기에 따른 차이 (0) | 2021.01.18 |