Fixed issues with the code.
Ok, I think I need to clarify the question.
new A.example(); outputs “A”
What should be inside the example method so that it could output “???”?
Is that even possible?
public class Letter {
public virtual void AsAString() {
Console.WriteLine("???");
}
public void example() {
this.AsAString();
}
}
public class A : Letter {
public override void AsAString() { Console.WriteLine("A"); }
public void example2() { base.AsAString(); }
}
new A().example2();
new A().example();
That’s very easy:
From that answer you should realise that what you actually asked for wasn’t what you thought that you asked for…
If you mean that you want to call the virtual method as if it wasn’t virtual, that is not possible. Even if you cast the reference to the base class, it still uses the actual type of the object to determine which method to call.