Files
2nd/10_Wiki/Dev/Topic_CSharp/CSharp_Inheritance.md
T
Antigravity Agent 1cfd3bbb56 docs(10_Wiki): 위키 구조 정리 — 언어 튜토리얼 카테고리 폴더 제거 + 신규 자산 동기화
Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고,
Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
2026-07-05 00:10:59 +09:00

5.2 KiB

id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
id title category status verification_status canonical_id aliases duplicate_of source_trust_level confidence_score created_at updated_at review_reason merge_history tags raw_sources applied_in github_commit
csharp-inheritance C# Inheritance Programming_Language draft conceptual
derived base class C#
sealed keyword C#
C# 상속
B 0.84 2026-07-04 2026-07-04
csharp
programming-language
w3schools
oop
inheritance
https://www.w3schools.com/cs/cs_inheritance.php

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]
  • : syntaxclass 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#):

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)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-07-04: Initial draft synthesized from the W3Schools "C# Inheritance" page (Astra wiki-curation, P-Reinforce v3.1 format).