https://msdn.microsoft.com/en-us/library/ebca9ah3.aspx

The override modifier is required to extend or modify the abstract or virtual implementation of an inherited method, property, indexer, or event.

Example

In this example, the Square class must provide an overridden implementation of Area because Area is inherited from the abstract ShapesClass:

  1. abstract class ShapesClass
  2. {
  3. abstract public int Area();
  4. }
  5.  
  6. class Square : ShapesClass
  7. {
  8. int side = ;
  9.  
  10. public Square(int n)
  11. {
  12. side = n;
  13. }
  14.  
  15. /// <summary>
  16. /// Area method is required to avoid a compile-time error.
  17. /// </summary>
  18. /// <returns></returns>
  19. public override int Area()
  20. {
  21. return side*side;
  22. }
  23.  
  24. internal static void Method()
  25. {
  26. Square sq = new Square();
  27. Console.WriteLine("Area of the square = {0}", sq.Area());
  28. }
  29.  
  30. interface I
  31. {
  32. void M();
  33. }
  34.  
  35. abstract class C : I
  36. {
  37. public abstract void M();
  38. }
  39.  
  40. }

An override method provides a new implementation of a member that is inherited from a base class.

The method that is overridden by an override declaration is known as the overridden base method.

The overridden base method must have the same signature as the override method.

For information about inheritance, see Inheritance (C# Programming Guide).

You cannot override a non-virtual or static method.

The overridden base method must be virtualabstract, or override.

An override declaration cannot change the accessibility of the virtual method.Both the override method and the virtual method must have the same access level modifier.

You cannot use the newstatic, or virtual modifiers to modify an override method.

An overriding property declaration must specify exactly the same access modifier, type, and name as the inherited property, and the overridden property must be virtualabstract, or override.

For more information about how to use the override keyword,

see Versioning with the Override and New Keywords (C# Programming Guide)

andKnowing when to use Override and New Keywords.

override (C# Reference)的更多相关文章

  1. abstract (C# Reference)

    https://msdn.microsoft.com/en-us/library/sf985hc5.aspx The abstract modifier indicates that the thin ...

  2. Spring3 整合Hibernate3.5 动态切换SessionFactory (切换数据库方言)

    一.缘由 上一篇文章Spring3.3 整合 Hibernate3.MyBatis3.2 配置多数据源/动态切换数据源 方法介绍到了怎么样在Sping.MyBatis.Hibernate整合的应用中动 ...

  3. 浅谈开源项目Android-Universal-Image-Loader(Part 3.1)

    本文转载于:http://www.cnblogs.com/osmondy/p/3266023.html 浅谈开源项目Android-Universal-Image-Loader(Part 3.1) 最 ...

  4. 【Java&Android开源库代码剖析】のAndroid-Universal-Image-Loader-part1

    做Android app开发的同学应该都听说过或者用过nostra13的Android-Universal-Image-Loader开源库,它在图片异步加载.缓存和显示等方面提供了强大灵活的框架.之前 ...

  5. Android -- ImageLoader简析

    图片的内存缓存实现 Image-Loader库有一个较完整的内存缓存实现,使用者可以根据需要选择已经实现的策略,也可以定制自己项目中需要的策略. 内存缓存实现代码在memory和memory.impl ...

  6. Java中的软(弱)引用

    一.Java中的强.软.弱.虚引用 在JDK中我们能够看到有一个java.lang.ref的包.这个包中就是Java中实现强.软.弱.虚引用的包,例如以下: PhantomReference 虚引用: ...

  7. ssh,hibernate动态映射多表

    [From] http://www.07net01.com/2016/01/1172051.html 最近在做OA系统(ssh),一直在想如何把框架架得更完善,此前已经在框架里集成springMVC, ...

  8. [原创] 浅谈开源项目Android-Universal-Image-Loader(Part 3.1)

    最近,总算有时间去做些平时喜欢而没空去做的事情.一直觉得项目中使用的Image Loader适用性不强,昨晚在github随便逛逛,发现一个开源项目Android-Universal-Image-Lo ...

  9. JNDI 笔记(一) 概述

    很多地方都会用到JNDI,一大堆的缩写加上一大堆不清不楚的概念描述,使得在看到的时候都不认识,更不要说使用了.   JNDI,Java Naming Directory Interface,J2EE的 ...

随机推荐

  1. thinkphp 5.0整合阿里大于验证码短信发送接口,含完整模型验证实例DEMO

    为大家分享一个阿里大于短信发送接口: 首先创建一个发送模型(Send.php): <?php namespace app\index\model; use think\Validate; cla ...

  2. 对 Spring IoC 的理解

    理解 “ 控制反转(IoC)” 控制反转(IoC):用白话来讲,就是由 Spring 容器控制程序中类与类之间的关系,而非传统实现中,由程序代码直接操控.这也就是所谓 “控制反转” 的概念所在:控制权 ...

  3. 【03】《论道html5》(全)

    [03]   <论道html5>   共320页. 魔芋:已看完.   读后感:html5各个新特性的介绍.介绍了canvas,web socket,audio,video,web wor ...

  4. java程序验证用户名密码和验证码登录的小例子

    package Study02; import java.util.Random; import java.util.Scanner; public class test { static Strin ...

  5. 2015 湘潭大学程序设计比赛(Internet)部分题解,其中有一个题与NYOJ1057很像,贪心过~~

    仙剑奇侠传                 祝玩的开心                                                                          ...

  6. hihoCoder#1077 RMQ问题再临-线段树

    原题地址 终于做到线段树的题了,因为建树.更新.查询都是递归操作,所以其实挺好写的. 用数组存的树,记得MAX_NODE开成两倍叶节点数大小,否则RE啊..不要问我是怎么知道的. 代码: #inclu ...

  7. [BZOJ2667][cqoi2012]模拟工厂

    [BZOJ2667][cqoi2012]模拟工厂 试题描述 有一个称为“模拟工厂”的游戏是这样的:在时刻0,工厂的生产力等于1.在每个时刻,你可以提高生产力或者生产商品.如果选择提高生产力,在下一个时 ...

  8. hdu 5093 二分匹配

    /* 题意:给你一些冰岛.公共海域和浮冰,冰岛可以隔开两个公共海域,浮冰无影响 求选尽可能多的选一些公共海域点每行每列仅能选一个. 限制条件:冰山可以隔开这个限制条件.即*#*可以选两个 预处理: * ...

  9. 2018/3/4 Activiti教程之对于流程的基本操作以及从发起到完成还有相关注意事项(与Springboot整合版)三

    写教程实在太累了,,,还浪费时间,Activiti教程就写到这好了,不过最近在玩区块链,到时候写几个区块链方面的教程. 这是一些流程的查询与删除api,删除这块,默认是级联删除(加个false参数,就 ...

  10. codevs——1275 有鱼的声音

    1275 有鱼的声音 2012年CCC加拿大高中生信息学奥赛  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 青铜 Bronze 题解  查看运行结果     题目描述 Des ...