Because you are missing the glaring warning in the IDE
Severity Code Description Project File Line Suppression State
Warning CS0108 'B.SomeMethod()' hides inherited member
'A.SomeMethod()'. Use the new keyword if hiding was intended.
Compiler Warning (level 2) CS0108
'member1' hides inherited member 'member2'. Use the new keyword if
hiding was intended.
A variable was declared with the same name as a variable in a base
class. However, the new keyword was not used. This warning informs you
that you should use new; the variable is declared as if new had been
used in the declaration.
If you want to hide it, use the new
keyword
However, if you want to call it then use virtual
and override
it, or just change the method name so you are not hiding it
class A
{
public virtual void SomeMethod()
{
Console.Write("This is A");
}
}
class B : A
{
public override void SomeMethod()
{
base.SomeMethod();
Console.Write("This is B");
}
public void OtherMethod()
{
Console.Write("This is New method");
}
}
virtual (C# Reference)
The virtual keyword is used to modify a method, property, indexer, or
event declaration and allow for it to be overridden in a derived
class. For example, this method can be overridden by any class that
inherits it:
override (C# Reference)
The override modifier is required to extend or modify the abstract or
virtual implementation of an inherited method, property, indexer, or
event.
Polymorphism (C# Programming Guide)
In the heap in this situation when created object instance, type
object pointer points to A or B?
You need not worry your self about what happens on the heap (these are implementation details), just what the language allows you to do.
However, A technically does not exist, there is only an instance of B, that has all the implementation of A (if you need it)