--- 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).