1cfd3bbb56
Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고, Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
86 lines
5.2 KiB
Markdown
86 lines
5.2 KiB
Markdown
---
|
|
id: csharp-inheritance
|
|
title: "C# Inheritance"
|
|
category: "Programming_Language"
|
|
status: "draft"
|
|
verification_status: "conceptual"
|
|
canonical_id: ""
|
|
aliases: ["derived base class C#", "sealed keyword C#", "C# 상속"]
|
|
duplicate_of: ""
|
|
source_trust_level: "B"
|
|
confidence_score: 0.84
|
|
created_at: 2026-07-04
|
|
updated_at: 2026-07-04
|
|
review_reason: ""
|
|
merge_history: []
|
|
tags: ["csharp", "programming-language", "w3schools", "oop", "inheritance"]
|
|
raw_sources: ["https://www.w3schools.com/cs/cs_inheritance.php"]
|
|
applied_in: []
|
|
github_commit: ""
|
|
---
|
|
|
|
# [[CSharp Inheritance]]
|
|
|
|
## 🎯 한 줄 통찰 (One-line insight)
|
|
C#'s inheritance syntax `class Car : Vehicle` OMITS the access specifier that C++'s equivalent `class Car : public Vehicle` REQUIRES — C# never lets you write `class Car : private Vehicle`, because member-level access (public/private/protected on each field/method) is the only lever C# offers, unlike C++ which layers an ADDITIONAL access specifier onto the inheritance relationship itself; and where C++ uses `final` to block further subclassing, C# uses a differently-named but functionally identical `sealed` keyword. [S1]
|
|
|
|
## 🧠 핵심 개념 (Core concepts)
|
|
- **Derived class (child)** — the class that inherits from another class. [S1]
|
|
- **Base class (parent)** — the class being inherited from. [S1]
|
|
- **`:` syntax** — `class Car : Vehicle` — no access specifier before the base class name, unlike C++'s `class Car : public Vehicle`. [S1]
|
|
- **Inherited members** — a derived class gains ALL fields and methods from its base class, callable/accessible directly on the derived class's own objects. [S1]
|
|
- **Motivation** — code reusability: reuse an existing class's fields/methods instead of rewriting them in the new class. [S1]
|
|
- **`sealed` keyword** — prevents a class from being inherited at all; attempting to derive from a sealed class is a compile error (`'Car': cannot derive from sealed type 'Vehicle'`). [S1]
|
|
|
|
## 📖 세부 내용 (Details)
|
|
- Full example: `class Vehicle { public string brand = "Ford"; public void honk() { Console.WriteLine("Tuut, tuut!"); } } class Car : Vehicle { public string modelName = "Mustang"; } ... Car myCar = new Car(); myCar.honk(); Console.WriteLine(myCar.brand + " " + myCar.modelName);` → calls the PARENT's `honk()` and reads the PARENT's `brand` field directly on a `Car` object, alongside `Car`'s own `modelName`. [S1]
|
|
- Sealed class blocking inheritance: `sealed class Vehicle { ... } class Car : Vehicle { ... }` → compile error. [S1]
|
|
- The tutorial explicitly points forward to Polymorphism as building on inherited methods to perform different tasks. [S1]
|
|
|
|
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
|
|
- **상속 문법에 접근 지정자가 없음**: C++는 `class Car : public Vehicle`처럼 상속 관계 자체에 public/private/protected 접근 지정자를 붙여야 했지만, C#은 `class Car : Vehicle`처럼 이 지정자 없이 상속하며, 접근 제어는 오직 멤버 단위(각 필드/메서드의 public/private/protected)로만 이뤄진다는 점이 확인됨. [S1]
|
|
- **final 대신 sealed라는 다른 이름의 동일 개념**: C++11의 `final` 키워드와 동일한 역할(더 이상 상속 불가)을 C#은 `sealed`라는 이름으로 제공한다는 점이 확인됨 — 개념은 같지만 키워드가 다름. [S1]
|
|
- **원문 구조상 상속이 단일 챕터로 압축됨**: Topic_CPP는 Inheritance/Access/Multilevel/Multiple을 4개 문서로 나눴지만, C# 사이드바는 cs_inheritance.php 단 하나로 기본 상속과 sealed를 모두 다룬다는 점이 확인됨 — 다단계·다중 상속에 대한 별도 챕터가 C# 튜토리얼에는 없음. [S1]
|
|
|
|
## 🛠️ 적용 사례 (Applied in summary)
|
|
Vehicle(부모)의 brand 필드와 honk() 메서드를 Car(자식)가 상속받아 Car 객체에서 그대로 사용하는 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1]
|
|
|
|
## 💻 코드 패턴 (Code patterns)
|
|
Inheritance without an access specifier on the base class (C#):
|
|
```csharp
|
|
class Vehicle
|
|
{
|
|
public string brand = "Ford";
|
|
public void honk()
|
|
{
|
|
Console.WriteLine("Tuut, tuut!");
|
|
}
|
|
}
|
|
class Car : Vehicle // no `public`/`private` before Vehicle, unlike C++
|
|
{
|
|
public string modelName = "Mustang";
|
|
}
|
|
|
|
Car myCar = new Car();
|
|
myCar.honk(); // inherited method
|
|
Console.WriteLine(myCar.brand + " " + myCar.modelName); // inherited field + own field
|
|
```
|
|
|
|
## ✅ 검증 상태 및 신뢰도
|
|
- **상태:** draft
|
|
- **검증 단계:** conceptual
|
|
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
|
|
- **신뢰 점수:** 0.84
|
|
- **중복 검사 결과:** 신규 생성 (New discovery)
|
|
|
|
## 🔗 지식 그래프 (Knowledge Graph)
|
|
- **상위/루트:** [[C# Tutorial]]
|
|
- **관련 개념:** [[CSharp Properties]], [[CSharp Polymorphism]], [[CPP Inheritance]]
|
|
- **참조 맥락:** Inheritance 섹션의 유일 챕터 — Polymorphism & Abstract 섹션으로 이어짐.
|
|
|
|
## 📚 출처 (Sources)
|
|
- [S1] W3Schools — C# Inheritance — https://www.w3schools.com/cs/cs_inheritance.php
|
|
|
|
## 📝 변경 이력 (Change history)
|
|
- 2026-07-04: Initial draft synthesized from the W3Schools "C# Inheritance" page (Astra wiki-curation, P-Reinforce v3.1 format).
|