Skip to content

Commit 91d3bac

Browse files
authored
Merge pull request #46 from InSeong-So/main
โœ๏ธ 6ํšŒ์ฐจ ๋ฌธ์„œ ์ถ”๊ฐ€ : ํด๋ž˜์Šค
2 parents ea32f4e + a01afaf commit 91d3bac

1 file changed

Lines changed: 197 additions & 0 deletions

File tree

โ€ŽJavascript/class.mdโ€Ž

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ํด๋ž˜์Šค ๊ธฐ๋ฐ˜์˜ ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๊ฐ€ ์•„๋‹ˆ์ง€๋งŒ ํ”„๋กœํ† ํƒ€์ž… ๊ธฐ๋ฐ˜์˜ ์•„์ฃผ ์œ ์—ฐํ•œ ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์Šคํƒ€์ผ๋กœ ๊ฐ์ฒด ์ง€ํ–ฅ ์–ธ์–ด์˜ ์ƒ์†๊ณผ ์บก์Аํ™” ๋“ฑ์˜ ์ถ”์ƒ์  ๊ฐœ๋…๋„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๋Š” ์ด ์žฅ์—์„œ ES6์— ๋“ฑ์žฅํ•œ ํด๋ž˜์Šค(Class)์— ๋Œ€ํ•ด ์•Œ์•„๋ด…๋‹ˆ๋‹ค.
2+
3+
## ํด๋ž˜์Šค์™€ ์ƒ์„ฑ์ž ํ•จ์ˆ˜
4+
> ES6์˜ ํด๋ž˜์Šค๊ฐ€ ํ”„๋กœํ† ํƒ€์ž… ๊ธฐ๋ฐ˜ ๊ฐ์ฒด ์ง€ํ–ฅ ๋ชจ๋ธ์„ ํ์ง€ํ•œ ๊ฒƒ์ด ์•„๋‹™๋‹ˆ๋‹ค. ํด๋ž˜์Šค๋„ ํ•จ์ˆ˜์ด๊ธฐ ๋•Œ๋ฌธ์ด์ง€์š”.
5+
6+
์šฐ๋ฆฌ๋Š” ๊ธฐ์กด ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ๊ตฌํ˜„ํ•  ๋•Œ, ์ƒ์„ฑ์ž ํ•จ์ˆ˜์™€ ํ”„๋กœํ† ํƒ€์ž…, ํด๋กœ์ €๋ฅผ ์ด์šฉํ•ด์™”์Šต๋‹ˆ๋‹ค.
7+
```js
8+
var Person = (function () {
9+
// Constructor, ์ƒ์„ฑ์ž ํ•จ์ˆ˜
10+
function Person(name) {
11+
this._name = name;
12+
}
13+
14+
// public method
15+
Person.prototype.sayHi = function () {
16+
console.log('HELLO! ' + this._name);
17+
};
18+
19+
// return constructor
20+
return Person;
21+
}());
22+
23+
// ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ
24+
var me = new Person('Amy');
25+
me.sayHi(); // HELLO! Amy
26+
27+
console.log(me instanceof Person); // true
28+
```
29+
30+
์ด๋ฅผ ํด๋ž˜์Šค๋กœ ๊ตฌํ˜„ํ•ด๋ณผ๊นŒ์š”?
31+
```js
32+
class Person {
33+
// constructor, ์ƒ์„ฑ์ž
34+
constructor(name) {
35+
this._name = name;
36+
}
37+
38+
sayHi() {
39+
console.log(`HELLO! ${this._name}`);
40+
}
41+
}
42+
43+
// ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ
44+
const me = new Person('Amy');
45+
me.sayHi(); // HELLO! Amy
46+
47+
console.log(me instanceof Person); // true
48+
```
49+
50+
๋™์ผํ•œ ๋™์ž‘์„ ํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ด์ฃ ? ๊ตฌ๋ฌธ๋„ ๋‹จ์ˆœํ™”๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ฆ‰, ES6์˜ ํด๋ž˜์Šค๋Š” ํ•จ์ˆ˜์ด๋ฉฐ ๊ธฐ์กด ํ”„๋กœํƒ€์ž… ๊ธฐ๋ฐ˜ ํŒจํ„ด์— **๋ฌธ๋ฒ•์  ์„คํƒ•(Syntactic sugar)** ์ด ๋ฉ๋‹ˆ๋‹ค. ๋‹จ, ํด๋ž˜์Šค์™€ ์ƒ์„ฑ์ž ํ•จ์ˆ˜๊ฐ€ ๋™์ผํ•˜๊ฒŒ ๋™์ž‘ํ•˜์ง€๋Š” ์•Š์œผ๋‹ˆ๊นŒ ์ฃผ์˜(์ผ๊ฐ์—์„  ์ด๋Ÿฐ ์ด์œ ๋กœ ํด๋ž˜์Šค๋ฅผ ๋ฌธ๋ฒ•์  ์„คํƒ•์œผ๋กœ ์ธ์ •ํ•˜์ง€ ์•Š์•„์š”)ํ•˜์„ธ์š”.
51+
52+
<br>
53+
54+
## ํด๋ž˜์Šค ์ •์˜
55+
> ํด๋ž˜์Šค๋Š” class ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ •์˜ํ•˜๋ฉฐ, ํŒŒ์Šค์นผ ์ผ€์ด์Šค๋กœ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ด ์ผ๋ฐ˜์ ์ž…๋‹ˆ๋‹ค.
56+
57+
ํด๋ž˜์Šค๋ฅผ ์–ด๋–ป๊ฒŒ ์ž‘์„ฑํ•˜๋Š”์ง€๋Š” ์–ธ๊ธ‰ํ•˜์ง€ ์•Š๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ธฐ์กด ํ”„๋กœํ† ํƒ€์ž…๊ณผ ์œ ์‚ฌํ•˜๊ธฐ ๋•Œ๋ฌธ์ด์ฃ . ์ด ์žฅ์—์„œ๋Š” ํด๋ž˜์Šค์˜ ํŠน์ง•๋งŒ ์งš๊ณ  ๋„˜์–ด๊ฐ‘๋‹ˆ๋‹ค.
58+
59+
1. ํด๋ž˜์Šค๋Š” ํด๋ž˜์Šค ์„ ์–ธ๋ฌธ ์ด์ „์— ์ฐธ์กฐํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.
60+
- ์ด๋Š” let, const์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ฆ‰, ํ˜ธ์ด์ŠคํŒ…๋˜๋‚˜ let, const ๋ณ€์ˆ˜์ฒ˜๋Ÿผ ์„ ์–ธ๋ฌธ ์ด์ „์— ์ผ์‹œ์  ์‚ฌ๊ฐ์ง€๋Œ€(TDZ)์— ๋น ์ง€๊ธฐ ๋•Œ๋ฌธ์ด์ฃ .
61+
- ํ˜ธ์ด์ŠคํŒ…์€ var, let, const, function, function*, class ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•œ ๋ชจ๋“  ์„ ์–ธ๋ฌธ์— ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.
62+
63+
<br>
64+
65+
2. ํ‘œํ˜„์‹์œผ๋กœ๋„ ํด๋ž˜์Šค๋ฅผ ์ •์˜ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ์ต๋ช…์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
66+
```js
67+
const NamedClass = class UnNamedClass {};
68+
69+
const name = new NamedClass();
70+
console.log(name); // UnNamedClass {}
71+
72+
new UnNamedClass(); // ReferenceError: UnNamedClass is not defined
73+
```
74+
- ํด๋ž˜์Šค๊ฐ€ ํ• ๋‹น๋œ ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ๊ธฐ๋ช… ํด๋ž˜์Šค๋กœ ์ƒ์„ฑํ•œ๋‹ค๋ฉด ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ์ด์œ ๋Š” **ํด๋ž˜์Šค ํ‘œํ˜„์‹์— ์‚ฌ์šฉํ•œ ์ด๋ฆ„์€ ์™ธ๋ถ€ ์ฝ”๋“œ์—์„œ ์ ‘๊ทผ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๊ธฐ ๋•Œ๋ฌธ์ด์ฃ **.
75+
76+
<br>
77+
78+
3. ์ƒ์„ฑ์ž ํ•จ์ˆ˜์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ new ์—ฐ์‚ฐ์ž์™€ ํ•จ๊ป˜ ํด๋ž˜์Šค๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
79+
```js
80+
class NamedClass {};
81+
const name = NamedClass(); // TypeError: Class constructor NamedClass cannot be invoked without 'new'
82+
```
83+
- ํด๋ž˜์Šค๋ฅผ new ์—ฐ์‚ฐ์ž ์—†์ด ํ˜ธ์ถœํ•˜๋ฉด ํƒ€์ž… ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.
84+
85+
<br>
86+
87+
4. ํด๋ž˜์Šค๋Š” ํด๋ž˜์Šค ๋‚ด๋ถ€์˜ ์บก์Аํ™”๋œ ๋ณ€์ˆ˜, **ํด๋ž˜์Šค ํ•„๋“œ(Class Field)** ๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค.
88+
- ๋ฐ์ดํ„ฐ ๋ฉค๋ฒ„, ๋ฉค๋ฒ„ ๋ณ€์ˆ˜๋ผ๊ณ ๋„ ๋ถ€๋ฅด๋ฉฐ ์ธ์Šคํ„ด์Šค์˜ ํ”„๋กœํผํ‹ฐ ํ˜น์€ ์ •์  ํ”„๋กœํผํ‹ฐ๊ฐ€ ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
89+
- this์— ์ถ”๊ฐ€ํ•œ ํ”„๋กœํผํ‹ฐ๋ฅผ ํด๋ž˜์Šค ๊ธฐ๋ฐ˜ ๊ฐ์ฒด์ง€ํ–ฅ ์–ธ์–ด์—์„œ ํด๋ž˜์Šค ํ•„๋“œ๋ผ๊ณ  ์ง€์นญํ•˜์ฃ .
90+
91+
<br>
92+
93+
5. constructor๋Š” ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ํด๋ž˜์Šค ํ•„๋“œ๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜๊ธฐ ์œ„ํ•œ ๋ฉ”์„œ๋“œ์ž…๋‹ˆ๋‹ค.
94+
```js
95+
class NamedClass {};
96+
const name = NamedClass(); // TypeError: Class constructor NamedClass cannot be invoked without 'new'
97+
// NamedClass๋Š” ์ƒ์„ฑ์ž ํ•จ์ˆ˜(constructor)์ž…๋‹ˆ๋‹ค.
98+
console.log(Object.getPrototypeOf(name).constructor === NamedClass); // true
99+
```
100+
- new ์—ฐ์‚ฐ์ž์™€ ํ•จ๊ป˜ ํ˜ธ์ถœ๋˜๋Š” ๊ฒƒ์ด constructor๋กœ ํŒŒ๋ผ๋ฏธํ„ฐ์— ์ „๋‹ฌํ•œ ๊ฐ’์€ ํด๋ž˜์Šค ํ•„๋“œ์— ํ• ๋‹นํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
101+
- constructor๋Š” ์ธ์Šคํ„ด์Šค์˜ ์ƒ์„ฑ๊ณผ ๋™์‹œ์— ํด๋ž˜์Šค ํ•„๋“œ์˜ ์ƒ์„ฑ๊ณผ ์ดˆ๊ธฐํ™”๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
102+
- constructor๋Š” ํด๋ž˜์Šค ๋‚ด์— ํ•œ ๊ฐœ๋งŒ ์กด์žฌํ•˜๋ฉฐ 2๊ฐœ ์ด์ƒ์ผ ๊ฒฝ์šฐ ๋ฌธ๋ฒ• ์—๋Ÿฌ(SyntaxError)๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.
103+
- constructor๋ฅผ ์ƒ๋žตํ•˜๋ฉด ํด๋ž˜์Šค์— constructor() {}, ์ฆ‰ ๋นˆ ๊ฐ์ฒด๋ฅผ ํฌํ•จํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค.
104+
105+
<br>
106+
107+
6. ํด๋ž˜์Šค ํ•„๋“œ์—๋Š” ๋ฉ”์„œ๋“œ๋งŒ ์„ ์–ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
108+
```js
109+
class NamedClass {
110+
name = ''; // SyntaxError
111+
112+
// ํด๋ž˜์Šค ํ•„๋“œ์˜ ์„ ์–ธ๊ณผ ์ดˆ๊ธฐํ™”๋Š” ๋ฐ˜๋“œ์‹œ constructor์—์„œ ์‹ค์‹œํ•ฉ๋‹ˆ๋‹ค.
113+
constructor(name) {
114+
this.name = name;
115+
}
116+
}
117+
```
118+
119+
> ํ˜„์žฌ๋Š” ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜๋Š”๋ฐ, TC39 ํ”„๋กœ์„ธ์Šค์˜ stage 3(candidate) ๋‹จ๊ณ„์— ์žˆ๋Š” ํด๋ž˜์Šค ๋ชธ์ฒด์—์„œ ์ง์ ‘ ์ธ์Šคํ„ด์Šค ํ•„๋“œ๋ฅผ ์„ ์–ธํ•˜๊ณ  private ์ธ์Šคํ„ด์Šค ํ•„๋“œ๋ฅผ ์„ ์–ธํ•  ์ˆ˜ ์žˆ๋Š” ํ”„๋กœํฌ์ ˆ(Class field declarations proposal)์˜ ํ•„๋“œ ์ •์˜๋ฅผ ์ตœ์‹  ๋ธŒ๋ผ์šฐ์ €์™€ ์ตœ์‹  Node.js๊ฐ€ ๊ตฌํ˜„ํ•˜์˜€๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.
120+
121+
<br>
122+
123+
- constructor ๋‚ด๋ถ€์—์„œ ์„ ์–ธํ•œ ํด๋ž˜์Šค ํ•„๋“œ๋Š” ํด๋ž˜์Šค๊ฐ€ ์ƒ์„ฑํ•  ์ธ์Šคํ„ด์Šค๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋Š” this์— ๋ฐ”์ธ๋”ฉ๋˜๋ฉฐ, ํด๋ž˜์Šค ์ธ์Šคํ„ด์Šค๋ฅผ ํ†ตํ•ด ์™ธ๋ถ€์—์„œ ์ง์ ‘ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. publicํ•œ ๋ฉค๋ฒ„๋กœ์„œ ์ทจ๊ธ‰๋˜๋Š” ๊ฒƒ์ด์ฃ .
124+
125+
<br>
126+
127+
> ์ตœ์‹  ๋ธŒ๋ผ์šฐ์ €์™€ Node.js 12๋ฒ„์ „ ์ด์ƒ์—์„œ๋Š” ์—ฌ๋Ÿฌ ์†์„ฑ๋“ค์„ ์ง€์›ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ [์—ฌ๊ธฐ](https://github.com/tc39/proposals/blob/master/README.md)๋ฅผ ์ฐธ์กฐํ•ด์ฃผ์„ธ์š”.
128+
129+
<br>
130+
131+
7. getter/setter๋กœ ํด๋ž˜์Šค ํ•„๋“œ์˜ ๊ฐ’์„ ์ฐธ์กฐํ•˜๊ฑฐ๋‚˜, ์กฐ์ž‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
132+
- ์šฐ๋ฆฌ๊ฐ€ ์•Œ๊ณ  ์žˆ๋Š” ๊ทธ ์ ‘๊ทผ์ž ํ”„๋กœํผํ‹ฐ๊ฐ€ ๋งž์Šต๋‹ˆ๋‹ค.
133+
134+
<br>
135+
136+
8. ์ •์ (static) ๋ฉ”์„œ๋“œ๋ฅผ ์ •์˜ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ํด๋ž˜์Šค ์ธ์Šคํ„ด์Šค๊ฐ€ ์•„๋‹ˆ๋ผ ํด๋ž˜์Šค ์ด๋ฆ„์œผ๋กœ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
137+
- ํด๋ž˜์Šค ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์ •์  ๋ฉ”์„œ๋“œ์— this๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
138+
```js
139+
class NamedClass {
140+
constructor(prop) {
141+
this.prop = prop;
142+
}
143+
144+
static staticMethod() {
145+
// ์ •์  ๋ฉ”์„œ๋“œ๋Š” this๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.
146+
// ์ •์  ๋ฉ”์„œ๋“œ ๋‚ด๋ถ€์—์„œ this๋Š” ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ์•„๋‹Œ ํด๋ž˜์Šค ์ž์‹ ์„ ๊ฐ€๋ฆฌํ‚ต๋‹ˆ๋‹ค.
147+
return 'staticMethod';
148+
}
149+
150+
prototypeMethod() {
151+
return this.prop;
152+
}
153+
}
154+
155+
// ์ •์  ๋ฉ”์„œ๋“œ๋Š” ํด๋ž˜์Šค ์ด๋ฆ„์œผ๋กœ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.
156+
console.log(NamedClass.staticMethod());
157+
158+
const name = new NamedClass(123);
159+
// ์ •์  ๋ฉ”์„œ๋“œ๋Š” ์ธ์Šคํ„ด์Šค๋กœ ํ˜ธ์ถœํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.
160+
console.log(name.staticMethod()); // Uncaught TypeError: NamedClass.staticMethod is not a function
161+
```
162+
- ์ด์œ ๋Š” ๊ธฐ์กด ํ”„๋กœํ† ํƒ€์ž… ๊ธฐ๋ฐ˜์˜ ๋ฌธ๋ฒ•์  ์„คํƒ•์ด ํด๋ž˜์Šค์ด๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ์œ„ ์˜ˆ์ œ๋ฅผ ES5๋กœ ํ‘œํ˜„ํ•ด ๋ณผ๊นŒ์š”?
163+
```js
164+
var NamedClass = (function () {
165+
// ์ƒ์„ฑ์ž ํ•จ์ˆ˜
166+
function NamedClass(prop) {
167+
this.prop = prop;
168+
}
169+
170+
NamedClass.staticMethod = function () {
171+
return 'staticMethod';
172+
};
173+
174+
NamedClass.prototype.prototypeMethod = function () {
175+
return this.prop;
176+
};
177+
178+
return NamedClass;
179+
}());
180+
181+
var name = new NamedClass(123);
182+
console.log(name.prototypeMethod()); // 123
183+
console.log(NamedClass.staticMethod()); // staticMethod
184+
console.log(name.staticMethod()); // Uncaught TypeError: name.staticMethod is not a function
185+
```
186+
- prototype ํ”„๋กœํผํ‹ฐ๋Š” ํ•จ์ˆ˜ ๊ฐ์ฒด๊ฐ€ ์ƒ์„ฑ์ž๋กœ ์‚ฌ์šฉ๋  ๋•Œ, ์ด ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ์ƒ์„ฑ๋œ ๊ฐ์ฒด์˜ ๋ถ€๋ชจ ์—ญํ• ์„ ํ•˜๋Š” ํ”„๋กœํ† ํƒ€์ž… ๊ฐ์ฒด๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋ฏ€๋กœ **์ •์  ๋ฉ”์„œ๋“œ์ธ staticMethod๋Š” ์ƒ์„ฑ์ž ํ•จ์ˆ˜ NamedClass์˜ ๋ฉ”์„œ๋“œ(ํ•จ์ˆ˜๋Š” ๊ฐ์ฒด์ด๋ฏ€๋กœ ๋ฉ”์„œ๋“œ๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์–ด์š”)์ด๊ณ , ์ผ๋ฐ˜ ๋ฉ”์„œ๋“œ์ธ prototypeMethod๋Š” ํ”„๋กœํ† ํƒ€์ž… ๊ฐ์ฒด NamedClass.prototype์˜ ๋ฉ”์„œ๋“œ์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ staticMethod๋Š” name์—์„œ ํ˜ธ์ถœํ•  ์ˆ˜ ์—†๋Š” ๊ฒƒ์ด์ฃ **!
187+
188+
<br>
189+
190+
9. extends ํ‚ค์›Œ๋“œ๋กœ ํด๋ž˜์Šค๋ฅผ ์ƒ์†(Class Inheritance) ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
191+
- ์˜ค๋ฒ„๋ผ์ด๋”ฉ(Overriding), ์˜ค๋ฒ„๋กœ๋”ฉ(Overloading)์ด ํ”„๋กœํ† ํƒ€์ž… ์ฒด์ธ์— ์˜ํ•ด ๊ตฌํ˜„๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
192+
- super() ํ‚ค์›Œ๋“œ๋กœ ๋ถ€๋ชจ ํด๋ž˜์Šค๋ฅผ ์ฐธ์กฐ(Reference)ํ•˜๊ฑฐ๋‚˜ ๋ถ€๋ชจ ํด๋ž˜์Šค์˜ constructor๋ฅผ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
193+
- ์ž์‹ ํด๋ž˜์Šค์—์„œ constructor๋ฅผ ์„ ์–ธํ•˜์ง€ ์•Š์œผ๋ฉด ๋ถ€๋ชจ์˜ constructor๋ฅผ ๋ฐ”๋ผ๋ด…๋‹ˆ๋‹ค.
194+
- ๊ทธ๋Ÿฌ๋‚˜ ์ž์‹ ํด๋ž˜์Šค์—์„œ constructor๋ฅผ ์„ ์–ธํ–ˆ์Œ์—๋„ super() ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ์ฐธ์กฐ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.
195+
196+
<hr>
197+
<br>

0 commit comments

Comments
ย (0)