메소드 은닉은 섀도잉이라고도 합니다. 섀도잉에서 override 키워드를 사용하지 않고도 부모 클래스의 메서드를 자식 클래스에서 사용할 수 있습니다. 자식 클래스에는 동일한 기능의 자체 버전이 있습니다.
새 키워드를 사용하여 섀도잉을 수행합니다.
예를 들어 보겠습니다.
예시
using System;
using System.Collections.Generic;
class Demo {
public class Parent {
public string GetInfo () {
return "This is Parent Class!";
}
}
public class Child : Parent {
public new string GetInfo() {
return "This is Child Class!";
}
}
static void Main(String[] args) {
Child child = new Child();
Console.WriteLine(child. GetInfo());
}
} 출력
This is Child Class!