c# 05抽象类

注意修饰符,父类的的抽象类和抽象方法的修饰符合class一起修饰的,子类实现父类的方法也带有“override”关键字

父类

 

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

namespace ConsoleApp1
{
    /// <summary>
    /// 蔬菜类
    /// </summary>
   abstract class Vegetables
    {
        /// <summary>
        /// 蔬菜的颜色
        /// </summary>
        public abstract void colour();
    }
}

 

 

 

子类

 

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

namespace ConsoleApp1 
{
    /// <summary>
    /// 胡萝卜类
    /// </summary>
     class Carrot : Vegetables
    {
        public static void Main(string[] args)
        {
            Carrot c = new Carrot();
            c.colour();
        }

       
        public override void colour()
        {
            Console.WriteLine("实现父类的方法因为父类是抽象的");
        }
    }
}

 

c# 05抽象类

上一篇:win7系统挂载Linux NFS


下一篇:2013-2014 Winter Petrozavodsk Camp, Andrew Stankevich Contest 45 (ASC 45) F - Flights