首页 > 其他 > 详细

重载OverLoad。隐藏new

时间:2014-09-19 19:25:16      阅读:222      评论:0      收藏:0      [点我收藏+]

<1>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{

    class A
    {
        public void SayHello()
        {
            Console.WriteLine("我是父类的SayHello方法");
        }
    }

    class B : A
    {
        public new void SayHello() //子类利用new关键字隐藏了父类的同名方法
        {
            Console.WriteLine("我是子类的SayHello方法");
        }
    }


    //构成方法重载的条件:<1>:函数名相同  <2>:参数类型不同,或者参数个数不同
    //注意:函数返回值类型的不同 不是函数重载的判断条件。
    class C
    {
        public void Add(int a,int b)
        {
            Console.WriteLine(a + b);
        }
        public double Add(double a, double b)
        {
            return a + b;
        }
        public void Add(int a)
        {
            Console.WriteLine(a);
        }

        public string Add(string a, string b)
        {
            return a + b;
        }
    }
    class Inheritance
    {
        static void Main(string[] args)
        {

            B b = new B();
            b.SayHello();



            Console.ReadKey();
        }
    }
}

重载OverLoad。隐藏new

原文:http://blog.csdn.net/fanbin168/article/details/39401473

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!