I’ve been thinking that if you’re familiar with Java, it won’t be difficult for you to write code in C# (or vice-versa). But now I realized that isn’t not going to be straight-forward:
class A {
protected void eat() {}
}
public class B extends A {
public static void test() {
A a = new B();
B b = new B();
a.eat();
b.eat();
}
}It’s absolutely legal in Java, but it doesn’t compile in C#:
class A {
protected void Eat() { }
}
class B : A {
public static void Test() {
A a = new B();
B b = new B();
a.Eat(); // Compile-time error:
//Cannot access protected member 'A.Eat()' via a qualifier of type 'A';
//the qualifier must be of type 'B' (or derived from it)
b.Eat();
}
}