Just look at the code.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace virtual function { class Base { virtual public void outClassName() { Console.WriteLine( "Base class" ); } virtual public void outPut() { Console.WriteLine("Base class"); } } class FirstDerived : Base { override public void outClassName() { Console.WriteLine("Of the first derived class outClassName Method"); } override public void outPut() { Console.WriteLine("In the first derived class outPut Method"); } } class SecondDerived : FirstDerived { public override void outClassName() { Console.WriteLine("Of the second derived class outClassName Method"); } new public void outPut() { Console.WriteLine("In the second derived class outPut Method"); } } class Program { static void Main(string[] args) { SecondDerived sd = new SecondDerived(); Base base1 = (Base)sd; base1.outPut();//The outPut method in the first derived class base1.outClassName();//outClassName method of the second derived class } } }
The original words in diagram C:
When an overridden method is called with a reference to the base class part of the object, the method call is executed along the derived class level up to the highest derived version of the method marked override. The key word of this sentence is to execute along the derived class level until the method marked override
That is to say, if the method is not traced back to the new tag.
Using new, as I understand it, is to cut off the method from the parent class The relation of the method with the same name and label in, so
new public void outPut()
{
Console.WriteLine("outPut method in the second derived class");
}
This method has nothing to do with the void outPut() method in the parent class. This method is not available for dynamic binding of natural wheels.