Here is a code sample:
class Program
{
static void Main(string[] args)
{
var obj = new DerivedClass();
obj.SomeMethod(5);
}
}
class
var obj = new DerivedClass();
var
keyword is just syntactic sugar in C#; this is essentially the same as:
DerivedClass obj = new DerivedClass();
hence you're calling DerrivedClass.SomeMethod
, which is just the behaviour you're experiencing. You would see a difference if you defined your variable like this:
BaseClass obj = new DerivedClass();