I'm C# programmer new to D language. I'm a bit to confused with OOP in D programming language.
Assuming that I have the following class:
public class A { protected void foo() { writefln("A.foo() called."); }};public class B : A { public override void foo() { writefln("B.foo() called."); }};
The protected
modifier means that I can access the .foo()
method just on inherited class,so why this D program compiles normally?
Here is the equivalent to 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(); }};
It don't compiles and given the following error message(as I expected):
test.cs(10,30): error CS0507:
B.foo()': cannot change access modifiers when overriding
protected' inherited member `A.foo()'
Can someone explain this D behavior? Thanks in advance.