zoukankan      html  css  js  c++  java
  • C#中Abstract 与 Virtual

    Abstract classes have the following features:

    • An abstract class cannot be instantiated.

    • An abstract class may contain abstract methods and accessors.

    • It is not possible to modify an abstract class with the sealed (C# Reference) modifier, which means that the class cannot be inherited.

    • A non-abstract class derived from an abstract class must include actual implementations of all inherited abstract methods and accessors.

    Use the abstract modifier in a method or property declaration to indicate that the method or property does not contain implementation.

    Abstract methods have the following features:

    • An abstract method is implicitly a virtual method.

    • Abstract method declarations are only permitted in abstract classes.

    • Because an abstract method declaration provides no actual implementation, there is no method body; the method declaration simply ends with a semicolon and there are no curly braces ({ }) following the signature.

    •  The implementation is provided by an overriding method override (C# Reference), which is a member of a non-abstract class.

    • It is an error to use the static or virtual modifiers in an abstract method declaration.

    Abstract properties behave like abstract methods, except for the differences in declaration and invocation syntax.

    • It is an error to use the abstract modifier on a static property.

    • An abstract inherited property can be overridden in a derived class by including a property declaration that uses the override modifier.

    When a virtual method is invoked, the run-time type of the object is checked for an overriding member. The overriding member in the most derived class is called, which might be the original member, if no derived class has overridden the member.

    By default, methods are non-virtual. You cannot override a non-virtual method.

    You cannot use the virtual modifier with the static, abstract, private or override modifiers.

    Virtual properties behave like abstract methods, except for the differences in declaration and invocation syntax.

    • It is an error to use the virtual modifier on a static property.

    • A virtual inherited property can be overridden in a derived class by including a property declaration that uses the override modifier.

  • 相关阅读:
    业余草双因素认证(2FA)教程
    业余草网站热门关键字
    微博爬虫“免登录”技巧详解及 Java 实现(业余草的博客)
    业余草通告CSDN博客用户zhang__ao非法转载文章的公告
    CODE大全给你推荐几个免费的leapftp 注册码
    业余草最新热门博客推荐
    莫比乌斯反演
    P5091 【模板】欧拉定理
    LaTeX Test
    P2742 [USACO5.1]圈奶牛Fencing the Cows /【模板】二维凸包
  • 原文地址:https://www.cnblogs.com/stragon/p/2093648.html
Copyright © 2011-2022 走看看