virtual methods

后端 未结 3 397
天命终不由人
天命终不由人 2021-01-28 12:01

If I have a class named \"Parent\" for example. he has a method named \"Print\". the class \"Kid\" is derived, it has a method named

3条回答
  •  醉梦人生
    2021-01-28 12:56

    When you use the new keyword with a method having same signature as that of a method in parent, it shadows the parent method. Shadowing is different from overriding. Shadowing means your new method will be called if both instance and variable are of type child. Whereas overriding ensures that your overriden method will be called no matter variable is of type child or parent.

    Edit:

    Take a look at the comparison sheet on MSDN.

提交回复
热议问题