代码之家  ›  专栏  ›  技术社区  ›  Alon Gubkin

抽象方法重写抽象方法

  •  5
  • Alon Gubkin  · 技术社区  · 15 年前
    public abstract class A
    {
        public abstract void Process();
    }
    
    public abstract class B : A
    {
        public abstract override void Process();
    }
    
    public class C : B
    {
        public override void Process()
        {
            Console.WriteLine("abc");
        }
    }
    

    有没有办法做到这一点?

    4 回复  |  直到 13 年前
        1
  •  13
  •   Razzie    15 年前

        2
  •  8
  •   Russell Mull    15 年前

    public abstract class A
    {
        public abstract void Process();
    }
    
    public abstract class B : A
    {
    }
    
    public class C : B
    {
        public override void Process()
        {
            Console.WriteLine("abc");
        }
    }
    
        3
  •  3
  •   Mark Bertenshaw    15 年前

    阿隆-

    -- 做记号

        4
  •  3
  •   Sam Harwell    15 年前

    public abstract class SomeBaseType
    {
        /* Override the ToString method inherited from Object with an abstract
         * method. Non-abstract types derived from SomeBaseType will have to provide
         * their own implementation of ToString() to override Object.ToString().
         */
        public abstract override string ToString();
    }
    
    public class SomeType : SomeBaseType
    {
        public override string ToString()
        {
            return "This type *must* implement an override of ToString()";
        }
    }