C# 가상 메서드 재로드 new 및 virtual
3562 단어 virtual
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OverrideTest
{
class A
{
private String username;
public void method1()
{
Console.WriteLine("A.method1");
}
// ,
public virtual void method2()
{
Console.WriteLine("A.method2");
}
}
class B : A
{
// , , 。
public new void method1()
{
Console.WriteLine("B.method1");
}
// , , 。
public override void method2()
{
Console.WriteLine("B.method2");
}
}
class Test {
public static void Main() {
B b = new B();
A a = b;
a.method1();
a.method2();
b.method1();
b.method2();
Console.Read();
}
}
}
결과 출력:
A.method1
B.method2
B.method1
B.method2
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[HDU 3172 Virtual Friends] 검색 집합 + map 포인터 최적화제목 링크: 제목: 친 구 를 찾 아 새로운 친 구 를 만나면 친구 들 을 합 쳐 총 친구 수 를 출력 한다.그렇지 않 으 면 이미 같은 곳 에 있다 면 직접 출력 하면 된다. 문제 풀이 방향: 뚜렷 하고 집합 을 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.