오버로딩은 같은 메서드 또는 생성자의 이름을 사용하지만, 매개변수의 개수, 타입 또는 순서를 다르게 정의하는 것이다.
class Calculator
{
public int Add(int a, int b) => a + b; // 정수형 더하기
public double Add(double a, double b) => a + b; // 실수형 더하기
}
오버라이딩은 부모 클래스에 정의된 메서드를 자식 클래스에서 새롭게 구현하는 것을 의미한다.
abstract class Animal
{
public abstract string GetSound();
}
class Dog : Animal
{
public override string GetSound() => "멍";
}
class Cat : Animal
{
public override string GetSound() => "야옹";
}