I have these classes:
class A
{
public int Foo()
{
return 5;
}
}
class B : A
{
public int Foo()
{
return 1;
}
}
and I use them like this:
B b = new B();
int x = b.Foo();
and although Foo() in the base class isn’t virtual, or in the derived class – it hasn’t the override keyword, still x equals 1. Then, what is the use of the virtual and override keywords?
Polymorphism allows type B to be treated as type A.