Skip to content

Commit 8dc7d3b

Browse files
committed
πŸš€[feat] μžλ°” - 클래슀, μƒμ„±μž, this
1 parent 95b7b5a commit 8dc7d3b

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package practiceJAVA;
2+
3+
public class Car {
4+
String company = "ferrari";
5+
String color;
6+
int maxSpeed;
7+
8+
// this 의 기반이 될 곡톡뢀뢄이 λ§Žμ€ μƒμ„±μž. πŸ”΄ this μ‚¬μš© μ‹œ, 이 곡톡 μƒμ„±μžμ˜ λ§€κ°œλ³€μˆ˜ μˆœμ„œλ₯Ό μ§€μΌœμ•Όν•¨.
9+
Car(String color, int maxSpeed) {
10+
this.color = color;
11+
this.maxSpeed = maxSpeed;
12+
}
13+
14+
Car(String color) {
15+
// 곡톡 μƒμ„±μž 호좜
16+
this(color, 100000);
17+
}
18+
Car(int maxSpeed) {
19+
// 곡톡 μƒμ„±μž 호좜
20+
this("red", maxSpeed);
21+
// this(maxSpeed, "red") [x] -> κ³΅ν†΅μƒμ„±μžμ™€ λ§€κ°œλ³€μˆ˜ μˆœμ„œκ°€ 닀름.
22+
}
23+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package practiceJAVA;
2+
3+
/**
4+
* μƒμ„±μž μ˜€λ²„λ‘œλ”©μ„ 톡해 μ½”λ“œ 쀑볡이 λ§Žμ•„μ§€λŠ” 경우λ₯Ό μ œμ–΄ κ°€λŠ₯ν•œ κΈ°λŠ₯
5+
* this
6+
*/
7+
8+
9+
public class ThisOfConstructor {
10+
public static void main(String[] args) {
11+
12+
Car newCar1 = new Car("red");
13+
System.out.println(newCar1.maxSpeed);
14+
15+
}
16+
}

0 commit comments

Comments
Β (0)