> For the complete documentation index, see [llms.txt](https://whs3-doge5k.gitbook.io/smartcontract-security-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whs3-doge5k.gitbook.io/smartcontract-security-docs/basics/2./undefined-2/is-override-virtual.md).

# 컨트랙트 상속 (is, override, virtual)

Solidity에서 컨트랙트를 **상속**하는 방법과 `override`, `virtual` 키워드의 의미를 이해합니다. 코드 재사용성과 확장 가능한 구조를 설계할 수 있습니다.

* Solidity는 **OOP(객체지향)** 개념을 차용하여 **상속 구조**를 지원합니다.
* `is` 키워드를 통해 부모 컨트랙트를 상속받습니다.
* 상속한 함수 중 재정의하려면 `override`, 부모 쪽에는 `virtual` 명시 필요

#### 예제

```solidity
contract Animal {
    function speak() public pure virtual returns (string memory) {
        return "sound";
    }
}

contract Dog is Animal {
    function speak() public pure override returns (string memory) {
        return "woof";
    }
}
```

| 키워드        | 의미                        |
| ---------- | ------------------------- |
| `is`       | 상속 지정                     |
| `virtual`  | 자식 컨트랙트에서 재정의 가능          |
| `override` | 부모의 virtual 함수를 재정의할 때 필요 |
