Skip to content

KO CSharp Inheritance Interfaces

Codex edited this page Oct 11, 2026 · 2 revisions

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

상속, 인터페이스 및 다형성

설명서 C# · 예시 UO

클래스에는 하나의 기본 클래스가 있으며 여러 인터페이스를 구현할 수 있습니다. virtual는 재정의를 허용하고, override는 이를 구현하고, abstract는 상속인의 구현을 요구하고, sealed는 상속을 제한합니다. base는 기본 구현을 나타냅니다. new는 멤버를 숨기고 override를 대체하지 않습니다.

간단한 예제 (Example.cs)

이 예제를 Example.cs로 따로 저장하고 이 페이지의 다른 예제와 독립적으로 실행하세요.

Example.cs:

// PROJECT-EXAMPLE
ILabel item = new Item();
System.Console.WriteLine(item.Label);
interface ILabel { string Label { get; } }
class Item : ILabel { public string Label => "Ore"; }

결과:

Ore
interface IDescription
{
    string Describe();
}

abstract class Job : IDescription
{
    public abstract string Describe();
}

sealed class GatherJob : Job
{
    public override string Describe() => "Gathering job";
}

IDescription job = new GatherJob();
UO.Print(job.Describe());
class NamedJob
{
    public string Name { get; }
    public NamedJob(string name) => Name = name;
    public virtual string Report() => Name;
}

sealed class TimedJob : NamedJob
{
    public TimedJob(string name) : base(name) { }
    public override string Report() => base.Report() + " — timed";
}

UO.Print(new TimedJob("Search").Report());

인터페이스는 완성된 게임 작업이 아닌 계약을 설명합니다. 인터페이스를 명시적으로 구현하면 동일한 이름의 멤버를 구분할 수 있습니다. 최신 C#는 적절한 일반 계약에서 기본 구현과 인터페이스의 정적 추상 멤버를 지원합니다.

공식 문서: 상속, 인터페이스 및 다형성 - Microsoft Learn.

Clone this wiki locally