오버로딩
- 동일한 이름으로 여러 개의 메서드를 작성
* 매개변수 개수, 형식이 다름
class Castle
{
public void animal() {
Console.WriteLine("동물이 없다.");
}
public void animal(string name) {
Console.Write( name + "가 있습니다.");
}
}
오버라이딩
- 기존에 있는 연산자를 재정의 하여 기존과 다른 기능을 수행하도록 함
* 부모 클래스의 메서드를 자식 클래스에서 재정의
class Road
{
public virtual void Move(string direction)
{
Console.WriteLine( direction+"로 움직인다.");
}
}
class Dragon : Road
{
public override void Move(string direction)
{
Console.WriteLine( direction +"의 반대로 움직인다.");
}
}
Road road = new Road();
road.Move("위");
Dragon dragon = new Dragon();
dragon.Move("아래");
Castle castle = new Castle();
castle.animal();
castle.animal("당나귀");
결 과
728x90
'C#' 카테고리의 다른 글
C# Task (0) | 2022.01.22 |
---|---|
1.22 영상 강의(16~20) 내용 정리 (0) | 2022.01.22 |
1.21 영상 강의(11~15) 내용 정리 (0) | 2022.01.21 |
1.20 영상 강의(6~10) 내용 정리 (0) | 2022.01.20 |
1.19 영상 강의(1~5) 내용 정리 (0) | 2022.01.19 |