Simple: at compile time, the system only knows that
obj
holds a class instance that implements ILastName:
ILastName obj=new MyName();
Because you have explicitly declared it as being of the type
ILastName
That you have assigned a
MyName
instance to it doesn't matter - the system can't be sure that at some point you won't assign a
MyOnlyNameIsMyLastName
instance, or a
ArtistFormerllyKnownAs
instance, even.
If you declare a variable as TypeX then you can only use properties, fields, and methods that are declared in TypeX or a class / Interface it acquires through inheritance - you cannot use anything that is declared in a derived class, because not all derived classes are required to implement it.