Предполагая, что у меня есть следующий класс:
Код: Выделить всё
public class A {
protected void foo() {
writefln("A.foo() called.");
}
};
public class B : A {
public override void foo() {
writefln("B.foo() called.");
}
};
Вот эквивалент в C#.NET:
Код: Выделить всё
using System;
public class A {
protected virtual void foo() {
Console.WriteLine("a.foo() called.");
}
};
public class B : A {
public override void foo() {
Console.WriteLine("b.foo() called.");
}
};
public class MainClass {
public static void Main(string[] args) {
A a = new A();
B b = new B();
a.foo();
b.foo();
}
};
test.cs(10 ,30): ошибка CS0507: B.foo()': невозможно изменить модификаторы доступа при переопределении protected' унаследованного члена `A.foo()'
Может кто-нибудь объяснить такое поведение D?
Подробнее здесь: https://stackoverflow.com/questions/104 ... e-every-wh
Мобильная версия