So I have this hierarchy:
They all have a method called helloWorld:
class A{
public virtual void helloWorld(){
Console.WriteLine("Hello, I am class A!");
...
}
class B:A{
public override void helloWorld(){
Console.WriteLine("Hello, I am class B!");
...
}
class C:B{
public new void helloWorld(){
Console.WriteLine("Hello, I am class C!");
...
}
It sounds reasonable to me that this code:
A a = new B();
a.helloWorld();
returns "Hello, I am class B!". Compiler gave priority to the most specific class implementation referenced.
But I can't understand why this code:
A a = new C();
a.helloWorld();
return "Hello, I am class B!", if no reference to class B has ever been made. Does any C# documentation explain the reason for that behaviour?
Edit: I think I got the concept of shadowing, but I still can't see why a non-referenced class is being called.