생성자
public class Mom
{
public Mom()
{
Console.Write("mom ");
}
}
public class Son : Mom
{
public Son()
{
Console.Write("son ");
}
}
public static void Main()
{
new Son(); // mom son
new Mom(); // mom
}
mom son
mom
상속
public class Mom
{
public void Print()
{
Console.Write("mom ");
}
}
public class Son : Mom
{
public void Print()
{
Console.Write("son ");
}
}
public static void Main()
{
var son = new Son();
son.Print(); // son
Mom mom = new Son();
mom.Print(); // mom
}
son
mom
오버라이딩
public abstract class Mom
{
public abstract void Print();
}
public class Son : Mom
{
public override void Print()
{
Console.Write("son ");
}
}
public static void Main()
{
var son = new Son();
son.Print(); // son
Mom mom = new Son();
mom.Print(); // son
}
son
son
가상함수 (2024/3/28 추가)
public class Mom
{
public virtual void Print()
{
Console.WriteLine("mom");
}
}
public class Son : Mom
{
public void Print()
{
Console.WriteLine("son");
}
}
public class Daughter : Mom
{
}
public static void Main()
{
var son = new Son();
var mom = new Mom();
var daughter = new Daughter();
son.Print(); // son
mom.Print(); // mom
daughter.Print(); // mom
}
가상함수 + (2024/3/28 추가)
public class Mom
{
public virtual void Print()
{
Console.WriteLine("mom");
}
}
public class Son : Mom
{
public void Print()
{
Console.WriteLine("son");
}
public void MomPrint()
{
base.Print();
}
}
public static void Main()
{
var son = new Son();
son.MomPrint(); // mom
Mom mom = new Son();
mom.Print(); // mom
}
'Server > C#' 카테고리의 다른 글
안정적인 서버를 구현하기 위한 잡지식 (0) | 2024.03.22 |
---|---|
SemaphoreSlim (1) | 2024.01.02 |
딕셔너리 vs 해시테이블 (2) | 2023.11.28 |
진짜 오랫동안 삽질했던, 프로그램 비정상 종료 대처법 (0) | 2023.10.11 |
C#의 장점 (2) | 2023.08.03 |
생성자
public class Mom
{
public Mom()
{
Console.Write("mom ");
}
}
public class Son : Mom
{
public Son()
{
Console.Write("son ");
}
}
public static void Main()
{
new Son(); // mom son
new Mom(); // mom
}
mom son
mom
상속
public class Mom
{
public void Print()
{
Console.Write("mom ");
}
}
public class Son : Mom
{
public void Print()
{
Console.Write("son ");
}
}
public static void Main()
{
var son = new Son();
son.Print(); // son
Mom mom = new Son();
mom.Print(); // mom
}
son
mom
오버라이딩
public abstract class Mom
{
public abstract void Print();
}
public class Son : Mom
{
public override void Print()
{
Console.Write("son ");
}
}
public static void Main()
{
var son = new Son();
son.Print(); // son
Mom mom = new Son();
mom.Print(); // son
}
son
son
가상함수 (2024/3/28 추가)
public class Mom
{
public virtual void Print()
{
Console.WriteLine("mom");
}
}
public class Son : Mom
{
public void Print()
{
Console.WriteLine("son");
}
}
public class Daughter : Mom
{
}
public static void Main()
{
var son = new Son();
var mom = new Mom();
var daughter = new Daughter();
son.Print(); // son
mom.Print(); // mom
daughter.Print(); // mom
}
가상함수 + (2024/3/28 추가)
public class Mom
{
public virtual void Print()
{
Console.WriteLine("mom");
}
}
public class Son : Mom
{
public void Print()
{
Console.WriteLine("son");
}
public void MomPrint()
{
base.Print();
}
}
public static void Main()
{
var son = new Son();
son.MomPrint(); // mom
Mom mom = new Son();
mom.Print(); // mom
}
'Server > C#' 카테고리의 다른 글
안정적인 서버를 구현하기 위한 잡지식 (0) | 2024.03.22 |
---|---|
SemaphoreSlim (1) | 2024.01.02 |
딕셔너리 vs 해시테이블 (2) | 2023.11.28 |
진짜 오랫동안 삽질했던, 프로그램 비정상 종료 대처법 (0) | 2023.10.11 |
C#의 장점 (2) | 2023.08.03 |