-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter12.java
More file actions
61 lines (47 loc) Β· 2.4 KB
/
Chapter12.java
File metadata and controls
61 lines (47 loc) Β· 2.4 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
60
61
package javastudy;
//ν΄λμ€ λ΄μλ ν΄λμ€ λ©€λ², μΈμ€ν΄μ€(κ°μ²΄) λ©€λ²λ‘ ꡬλΆν΄μ μμ±νλ€
//ν΄λμ€ λ©€λ² : κ°μ²΄λ₯Ό μμ±νμ§ μμλ λ°λ‘ μ¬μ©μ΄ κ°λ₯νλ€
//-> ν΄λμ€ λ©μλ νΈμΆ : ν΄λμ€λͺ
.λ©μλλͺ
//μΈμ€ν΄μ€(κ°μ²΄) λ©€λ² : κ°μ²΄λ₯Ό μμ± ν΄μΌλ§ μ¬μ©μ΄ κ°λ₯νλ€
//-> μΈμ€ν΄μ€(κ°μ²΄) λ©μλ νΈμΆ : κ°μ²΄λ₯Ό μμ±νκ³ κ°μ²΄λͺ
(λ³μλͺ
).λ©μλλͺ
()
//static(ν΄λμ€) λ©μλλ static(ν΄λμ€) λ©μλλ§ νΈμΆν μ μλ€
//static(ν΄λμ€) λ©μλλ μΈμ€ν΄μ€(κ°μ²΄) λ©μλλ₯Ό νΈμΆν μ μλ€ -> μμ§ κ°μ²΄κ° λ§λ€μ΄μ§μ§ μμκΈ° λλ¬Έ
//μΈμ€ν΄μ€(κ°μ²΄) λ©μλλ static(ν΄λμ€) λ©μλλ₯Ό νΈμΆν μ μλ€
class Method {
//λ©μλ μμ± νμ ) λ°ν κ° μλ£ν λ©μλλͺ
(λ§€κ°λ³μ or μΈμ) { μ²λ¦¬ κ³Όμ return λ°ν κ°; }
static void printName() {
System.out.println("printName μ€ν");
//printId(); ν΄λμ€ λ©μλλ μΈμ€ν΄μ€ λ©μλλ₯Ό νΈμΆν μ μλ€
return; //ν΄λμ€ λ©€λ²
}
void printEmail() {
System.out.println("printEmail μ€ν");
printId(); //μΈμ€ν΄μ€λ μΈμ€ν΄μ€λΌλ¦¬ 곡μ ν μ μλ€
return; //μΈμ€ν΄μ€ λ©€λ²
}
void printId() {
System.out.println("printId μ€ν");
printName(); //static(ν΄λμ€) λ©μλλ₯Ό νΈμΆν μ μλ€
//μΈμ€ν΄μ€ λ©μλλ κ°μ²΄λ₯Ό λ§λ€μ΄μΌλ§ νΈμΆμ΄ κ°λ₯ν κ²μ΄κΈ° λλ¬Έμ
//μ΄λ―Έ λ§λ€μ΄μ Έ μλ static λ©μλλ₯Ό νΈμΆν μ μλ€
return; //μΈμ€ν΄μ€ λ©€λ²
}
}
public class Chapter12 {
public static void main(String[] args) {
//κ°μ²΄λ₯Ό μμ±νμ§ μκ³ λ°λ‘ static(ν΄λμ€) λ©μλλ₯Ό νΈμΆν΄μ μ¬μ©
//ν΄λμ€λͺ
.λ©μλλͺ
();
Method.printName();
System.out.println("----------------");
//κ°μ²΄ μμ± : μΈμ€ν΄μ€(κ°μ²΄) λ©μλλ κ°μ²΄λ₯Ό μμ±ν΄μΌλ§ νΈμΆν μ μλ€
int a = 10;
Method m = new Method();
m.printName(); //static(ν΄λμ€) λ©μλλ κ°μ²΄λ₯Ό μμ±ν΄λ, μ ν΄λ μ¬μ©ν μ μμ
m.printId(); //μΈμ€ν΄μ€ λ©μλ νΈμΆ
System.out.println("----------------");
m.printEmail(); //μΈμ€ν΄μ€ λ©μλ νΈμΆ
System.out.println("----------------");
m.printEmail(); //μΈμ€ν΄μ€ λ©μλ νΈμΆ
System.out.println("----------------");
}
}