7.3抽象类,抽象方法

例:

namespace ConsoleApplication1
{
    abstract class A     //抽象类声明
     {
         abstract public int fun();   //抽象方法声明
    }
    class B : A
    {
        int x, y;
        public B(int x1, int y1)   //抽象方法实现
        {
            x = x1; y = y1;
        }
        public override int fun()  //重写,实现
        {
            return x * y;
        }
    }
    class Class4
    {
        public static void Main(string[] args)
        {
            B b = new B(2,3);
            A a = new B(2,4);
            Console.WriteLine("{0}", b.fun());
            Console.WriteLine("{0}", a.fun());
            Console.ReadLine();
        }
    }
}

 

 

posted on 2013-01-31 15:44  msony210  阅读(102)  评论(0)    收藏  举报

导航