To speak new, virtual, override

Source: Internet
Author: User

Let's look at the following procedure:

/// <summary>
   /// 父类
/// 作者:周公
/// 首发地址:http://blog.csdn.net/zhoufoxcn/archive/2008/09/02/2864429.aspx
/// 日期:2008-09-01
   /// </summary>
   public class Father
   {
     public void Run0()
     {
       Console.WriteLine("Father.Run0");
     }
   }
   /// <summary>
/// 子类
/// 作者:周公
/// 首发地址:http://blog.csdn.net/zhoufoxcn/archive/2008/09/02/2864429.aspx
/// 日期:2008-09-01
   /// </summary>
   public class Son:Father
   {
     public void Run0()
     {
       Console.WriteLine("Son.Run0");
     }
}
class Program
   {
     static void Main(string[] args)
     {
     Father[] fatherList = new Father[2];
       fatherList[0] = new Father();
       fatherList[1] = new Son();
       fatherList[0].Run0();
       fatherList[1].Run0();
   }
}

The results of the program's operation are:

Father.Run0
Father.Run0

A slightly attentive friend may find a brown wavy line under the Run0 method of the son class, and when we put the mouse over the underline, we see the following hint (this warning is also visible in the program's Output window when the program is compiled):

"MethodDemo.Son.Run0 ()" Hides the inherited member "MethodDemo.Father.Run0 ()". If you want to hide it intentionally, use the keyword new.

As shown in figure:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.