标题:疑问
只看楼主
whqfd
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-12-11
 问题点数:0 回复次数:0 
疑问
到底会call哪个Test method呢?欢迎讲出原因!
class Program
    {

        static void Main(string[] args)
        {

            DerivedClass dc = new DerivedClass();
 

            int i = 5;
            dc.Test(i);
            ((BaseClass)dc).Test(i);

            Console.ReadLine();
        }
    }
 

public class BaseClass
    {

        public virtual void Test(int i)
        {
            Console.WriteLine("BaseClass.Test(int i)");
        }
    }

    public class DerivedClass : BaseClass
    {
        public override void Test(int i)
        {
            Console.WriteLine("DerivedClass.Test(int i)");
        }
 
       public void Test(double i)
        {
            Console.WriteLine("DerivedClass.Test(double i)");
        }

    }
搜索更多相关主题的帖子: 疑问 
2008-01-10 13:21



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-196850-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.422229 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved