A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 武江英 中级黑马   /  2012-10-28 19:44  /  1438 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

用base关键字调用父类的方法
谁有例子来一个。

1 个回复

倒序浏览
class Program
    {
        static void Main(string[] args)
        {
         
            student St1 = new student();
            St1.Pclass();
            Dstudent Ds1 = new Dstudent();
            Ds1.Pclass();
            Console.ReadKey();
        }
    }
    class student
    {

        public  void Pclass()
        {
            Console.WriteLine("我是父类方法");
        }

    }
    class Dstudent:student
    {

        public new  void Pclass()
        {
            Console.Write("我是子类方法后面跟的是我通过Base调用的父类方法->");
            base.Pclass();
        }
  
    }
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马