# Overriding

오버로딩(Overloading)은 같은 이름, 다른 매개변수를 가진 메소드가 여러 개 존재하는 것을 말한다. 매개변수가 다르면 다른 메소드임을 알 수 있기 때문에 가능한 기능인데, 자바스크립트에서는 기본적으로 불가능하다. (대신 [매개변수의 존재 여부에 따라 분기를 나누는 방식](https://stackoverflow.com/questions/456177/function-overloading-in-javascript-best-practices)으로 구현할 수는 있다.) 한 클래스 안에 같은 이름을 가진 메소드가 여러 개 존재할 수 없으며, constructor도 반드시 하나만 있어야 한다.

오버라이딩(Overriding)은 subclass가 superclass의 메소드를 덮어쓰는 것을 말한다. 먼저 Food클래스에 `makeNoise()` 메소드를 추가했다.

```javascript
// Food.js
class Food{
    constructor(name) {
        this.name = name;
    }
    
    getName() {
        return this.name;
    }
    
    makeNoise() {
        console.log('It makes a noise');
    }
}

export default Food;
```

&#x20;Deep 클래스에 같은 이름의 메소드 `makeNoise()`를 정의했다.

```javascript
// Deep.js
import Food from './Food';

class Deep extends Food{
    constructor(name) {
        super(name);
    }
    
    // Override
    makeNoise() {
        console.log('Bark!');
    }
}

export default Deep ;
```

&#x20;Food클래스의 `makeNoise()`가 Deep 클래스의 `makeNoise()`로 오버라이드된 것을 볼 수 있다.

```javascript
// index.js
import Deep from './Deep';

let jake = new Deep('Jake');

console.log(jake.getName()); // 'Jake'
jake.makeNoise(); // 오버라이드된 결과 'Bark!' 
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://triplexlab.gitbook.io/vanilla-js/basics/09-prototype-class/overriding.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
