abstract、virtual、override 和 new

【C#】面向对象(17)——抽象类abstract(2)——虚方法virtual(1)——方法重写override(1)——知识点:虚方法,方法重写,抽象类,多态,接口 1、虚方法:使用virtual关键字修饰,使用virtual关键字修饰的方法在本类中必须有实现,哪怕是空的{}。虚方法存在的意义就是为了让子类重写。子类可以重写,也可以不重写。子类重写时使用override关键字。 Virtual写在返回类型的前面,即public virutal或virtual public。 2、方法重写:只有用virtual、abstract、override修饰的方法在继... 阅读详情

来自:http://www.cnblogs.com/ibmfm/archive/2008/12/31/1366153.html  

abstract、virtual、override 和 new 是在类的继承关系中常用的四个修饰方法的关键字,在此略作总结。

1. 常用的中文名:abstract 抽象方法,virtual 虚方法,override 覆盖基类方法,new 隐藏基类方法,override 和 new 有时都叫重写基类方法。

2. 适用场合:abstract 和 virtual 用在基类(父类)中;override 和 new 用在派生类(子类)中。

3. 具体概念:

    abstract 抽象方法,是空方法,没有方法体,派生类必须以 override 实现此方法。

    virtual 虚方法,若希望或预料到基类的这个方法在将来的派生类中会被重写(override 或 new),则此方法必须被声明为 virtual。

    override 重写继承自基类的 virtural 方法,可以理解为拆掉老房子,在原址上建新房子,老房子再也找不到了(基类方法永远调用不到了)。

    new 隐藏继承自基类的 virtual 方法,老房子还留着,在旁边盖个新房,想住新房住新房(作为派生类对象调用),想住老房住老房(作为基类对象调用)。

    当派生类中出现与基类同名的方法,而此方法前面未加 override 或 new 修饰符时,编译器会报警告,但不报错,真正执行时等同于加了 new。

4. abstract 和 virtual 的区别:abstract 方法还没实现,连累着基类也不能被实例化,除了作为一种规则或符号外没啥用;virtual 则比较好,派生类想重写就重写,不想重写就吃老子的。而且继承再好也是少用为妙,继承层次越少越好,派生类新扩展的功能越少越好,virtual 深合此意。

5. override 和 new 的区别:当派生类对象作为基类类型使用时,override 的执行派生类方法,new 的执行基类方法。如果作为派生类类型调用,则都是执行 override 或 new 之后的。


演示 override 和 new 区别的例子:

Code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->// Define the base class
class Car
{
   
public virtual void DescribeCar()
   {
       System.Console.WriteLine(
"Four wheels and an engine.");
   }
}

// Define the derived classes
class ConvertibleCar : Car
{
   
public new virtual void DescribeCar()
   {
       
base.DescribeCar();
       System.Console.WriteLine(
"A roof that opens up.");
   }
}
class Minivan : Car
{
   
public override void DescribeCar()
   {
       
base.DescribeCar();
       System.Console.WriteLine(
"Carries seven people.");
   }
}
public static void TestCars1()
{
   Car car1 
= new Car();
   car1.DescribeCar();
   System.Console.WriteLine(
"----------");

   ConvertibleCar car2 
= new ConvertibleCar();
   car2.DescribeCar();
   System.Console.WriteLine(
"----------");

   Minivan car3 
= new Minivan();
   car3.DescribeCar();

   System.Console.WriteLine("----------");

}

 

输出类似如下所示:

Four wheels and an engine.

----------

Four wheels and an engine.

A roof that opens up.

----------

Four wheels and an engine.

Carries seven people.

----------

但是,如果我们声明一个从 Car 基类派生的对象的数组。此数组能够存储 Car、ConvertibleCar 和 Minivan 对象,如下所示:

Code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->public static void TestCars2()
{
    Car[] cars 
= new Car[3];
    cars[
0] = new Car();
    cars[
1] = new ConvertibleCar();

    cars[2] = new Minivan();

}

 

然后用一个 foreach 循环来访问该数组中包含的每个 Car 对象,并调用 DescribeCar 方法,如下所示:

Code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->foreach (Car vehicle in cars)
{
  System.Console.WriteLine(
"Car object: " + vehicle.GetType());
  vehicle.DescribeCar();

  System.Console.WriteLine("----------");

}

 

此循环的输出如下所示:

Car object: YourApplication.Car

Four wheels and an engine.

----------

Car object: YourApplication.ConvertibleCar

Four wheels and an engine.

----------

Car object: YourApplication.Minivan

Four wheels and an engine.

Carries seven people.

----------

注意,ConvertibleCar 的说明可能与您的预期不同。由于使用了 new 关键字来定义此方法,所调用的不是派生类方法,而是基类方法。Minivan 对象正确地调用重写方法,并产生预期的结果。

华为面试手撕真题【最长不重复子串】 给定一个字符串s,请你找出其中不含有重复字符的最长子串的长度。 阅读详情

相关推荐

数据清洗(Data Cleansing)

数据清洗(Data Cleansing)是指对数据进行处理和纠错,以去除或修复数据集中存在的错误、不致、不完整和冗余的数据,从而使数据更加准确、可靠和有用。数据清洗是数据处理和数据分析中一个非常重要的步骤,它可以帮助我们提高数据的质量,从而提高数据分析和机器学习的准确性和可靠性。数据清洗是一个重要的过程,它可以帮助我们提高数据的质量,从而提高数据分析和机器学习的准确性和可靠性。在实际应用中,我们可以使用一些工具和技术来实现数据清洗,例如 Pandas、NumPy 和 OpenRefine 等。通过数据清洗,

meimei169500的博客 1万+

转载:abstract、virtual、override 和 new

abstract、virtual、override 和 new 是在类的继承关系中常用的四个修饰方法的关键字,在此略作总结。1. 常用的中文名:abstract 抽象方法,virtual 虚方法,override 覆盖基类方法,new 隐藏基类方法,override 和 new 有时都叫重写基类方法。2. 适用场合:abstract 和 virtual 用在基类(父类)中;override...

weixin_34343308的博客 169

Temporal Anti-Aliasing(时域抗锯齿TAA)

首先说一下走样:一般分为时域走样(如旋转车轮)和空域走样(锯齿),但在 TAA 技术是采用时域相关叠加混合技术来解决空域走样的问题。 简单看一下空域抗锯齿 (Spatial Anti-Aliasing, SAA)相关技术,最普及的莫过于 MSAA,被各大渲染引擎采用,但是 MSAA 并不适用于延迟渲染 (Deferred Rendering),随之出现了很多基于形态学的后处理抗锯齿技术,如 MLAA,FXAA,SMAA 等(具体看参见图形_反走样技术总结相关介绍),虽然他们表现良好且支持延迟渲染,但是都会面

qq_35312463的博客 1万+

C#中Abstract、Virtual和Override的使用方法

abstract、virtual和override

weixin_44171249的博客 862

农业杂草检测——棉花杂草数据集

然后将本层13×13的特征图谱经过×2上采样扩充到26×26,并与上层中26×26的特征图谱拼接,得到新的26×26的特征图谱,在该特征尺度上进行第二次预测,此时得到的特征图谱是相对输入图像16倍下采样,具有中尺度感受野,适合检测中等尺度对象;通过目标检测,能够及时清除杂草,减少病虫害的滋生和传播,保障棉花的健康生长,并有助于降低生产成本。对于地膜覆盖的棉田,由于膜内耕作层土温高、底墒好,杂草出苗早而集中,一般覆膜后5 - 7天杂草陆续出土,在墒情好的情况下,15天左右即形成出土高峰。

qq_38220914的博客 1245

MoveIt控制睿尔曼RM65机械臂:从仿真到实机的3种控制模式对比

本文详细解析了使用MoveIt框架控制睿尔曼RM65机械臂的三种核心模式:拖动规划、目标姿态规划和Python API控制,从Gazebo仿真到实机部署的完整实现路径。通过ROS环境配置、控制参数优化及实机过渡技术,为工业自动化和机器人研究提供实用指南。

727

一次搞懂C#的关键字abstract、override、virtual的区别与用法

** 一次搞懂C#的关键字abstract、override、virtual的区别与用法 ** 其实编码相当于翻译,我们要从英文翻译成机器能懂的语言,而编程语言要学懂,需要翻译成我们能理解的汉语。 virtual 很接近的;几乎…的;事实上的;实际上的;实质上的;(通过计算机软件,如在互联网上**)模拟的,虚拟的** abstract: 抽象的(与个别情况相对);纯理论的;抽象的(与具体经验相对);抽象(派)的 override :(以权力)否决,推翻,不理会;比…更重要;凌驾;超驰控制,超控(使自动控制暂

xuexixuexizai的博客 1779

华为云Stack扩容实战:从CMDB配置到计算节点增减容,一份避坑指南

本文详细解析华为云Stack扩容实战,从CMDB配置到计算节点增减容的全流程操作指南。通过典型场景案例和避坑建议,帮助企业高效管理计算资源扩容与减容,确保业务连续性。特别针对华为云Stack的弹性扩容能力提供专业指导,涵盖存储、网络及自动化工具链的配合使用。

weixin_30591551的博客 479

Abstract,Override

在上面的例子中,`Cat` 类继承了 `Animal` 抽象类,并重写了其中的 `sound` 方法。总之,`abstract` 和 `override` 是 Java 中常用的关键字,用于定义抽象类和抽象方法,以及重写父类的方法。它们的使用可以让程序更加灵活和可维护。在 Java 中,`abstract` 和 `override` 是两个关键字,分别用于定义抽象类和方法,以及重写父类的方法。- 子类重写父类方法时,需要使用`@Override`注解来标识,这样可以确保方法名和签名与父类方法一致。

2301_76948328的博客 351

保姆级教程:从OrthoFinder到CAFE5,手把手搞定基因家族收缩扩张分析(附完整代码与避坑指南)

本文提供从OrthoFinder到CAFE5的基因家族收缩扩张分析全流程教程,涵盖数据预处理、系统发育树准备、CAFE5运行与参数优化等关键步骤。通过详细代码示例和避坑指南,帮助研究者高效完成基因家族进化分析,特别适合生物信息学初学者。

dianshu1593的博客 390

NVIDIA Isaac ROS - 入门教程(一)

欢迎访问 Isaac ROS,这是一套硬件加速、高性能、低延迟的 ROS 2 软件包,用于制造自主机器人,充分利用 Jetson 和其他英伟达平台的强大功能。英伟达 Jetson 平台运行在基于 Ubuntu Linux 的 JetPack 操作系统上。JetPack 5.x 是在 Ubuntu 20.04 Focal 的基础上构建的,这意味着由 ROS 2 Buildfarm 为 Ubuntu 22.04 Jammy 构建的 ROS 2 Humble 的 Debian 包不受支持。由于官方 ROS 2 B

机器人控制与仿真应用 5721

C#区分abstract、virtual、override和new

abstract、virtual、override和new是在类别的继承关系中常用的四个修饰方法的关键字,在此略作总结。 1. 常用的中文名称: abstract => 抽象方法。  virtual => 虚拟方法。 override => 覆盖基础类别方法。 new => 隐藏基础类别方法。 override 和 new 有时都叫复写基

stod500的专栏 576

华为OD机试真题 新系统【小花获胜的奶茶】

华为OD机试真题 新系统【小花获胜的奶茶】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题 【小花获胜的奶茶】多语言题解。

qq_45776114的博客 382

virtual/abstract 和 override/new/sealed

virtual 表示父类中方法可被重写(父类中未声明为virtual的即不可被重写); abstract 表示方法为抽象类,声明时不含方法体,且所在类也需变为抽象类; override 表示子类中重写的方法(父类中被继承的方法应该是virtual或abstract) new 表示覆盖父类中的方法,不管该方法是否是可重写的,均可覆盖 sealed 表示密封/保护子类中继承父类的方法,非继承方...

化甘 245

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

abstract、virtual、override 和 new(转)

abstract、virtual、override 和 new 是在类的继承关系中常用的四个修饰方法的关键字,在此略作总结。 1. 常用的中文名:abstract 抽象方法,virtual 虚方法,override 覆盖基类方法,new 隐藏基类方法,override 和 new 有时都叫重写基类方法。 2. 适用场合:abstract 和 virtual 用在基类(父类)中;override

首席科学家的专栏 496

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

C#中的abstract、virtual、override和new

梳理一下static、abstract、virtual、override和new之间的关系 ①static类里的所有成员都应该是static的,且不能被继承,static的方法也不能加abstract或virtual; 但是在非static类里面的static方法可以在子类中被同名方法覆盖, //父类 public class ClassBase { public...

weixin_30877227的博客 123

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

C#继承中abstract、virtual、override和new

abstract 详细参考:https://msdn.microsoft.com/zh-cn/library/sf985hc5.aspx abstract 修饰符指示所修饰的内容缺少实现或未完全实现。 abstract 修饰符可用于类、方法、属性、索引器和事件。 在类声明中使用 abstract 修饰符以指示某个类只能是其他类的基类。 标记为抽象或包含在抽象类中的成员必须通过从抽象类派生的

tanzhangwen的专栏 1892

new、abstract、virtual、override,sealed关键字区别和使用代码示例

using System; namespace Text3 {     //new、abstract、virtual、override,sealed关键字区别和使用代码示例     //new 与 override的区别          //覆写(override)与重载(overload),是成就.NET面向对象多态特性的基本技术之一     //正如某网友说的那一句

Violinlins 893

工业级步进电机控制:DRV8818与PIC18F47K40硬实时协同设计

步进电机控制是运动控制系统的基础技术,其核心在于相电流的精确调控与微步时序的确定性执行。原理上依赖PWM斩波、电流反馈闭环与硬件级定时协同;技术价值体现在高重复精度(±0.02mm)、宽温区稳定性(-40℃~125℃)及抗干扰鲁棒性;广泛应用于CNC定位、SCARA机器人关节、视觉检测平台等对实时性与可靠性要求严苛的工业场景。本文聚焦DRV8818PWPR的RDS(on)电流检测补偿机制与PIC18F47K40的ECCP硬件步进脉冲生成能力,解析如何在8位资源受限平台上构建具备PLC级响应特性的嵌入式运动控

weixin_34082854的博客 314

[C#] 區分 abstract、virtual、override 和 new

abstract、virtual、override和new是在類別的繼承關係中常用的四個修飾方法的關鍵字,在此略作總結。 1.常用的中文名稱: nabstract =>抽象方法。 nvirtual =>虛擬方法。 noverride =>覆蓋基礎類別方法。 nnew =>隱藏基礎類別方法。 noverride和new...

weixin_33719619的博客 105

C#中的virtual,abstract,override和new关键字小结

C#中virtual,abstract,override用于方法重载,子类覆盖了父类的相同方法,父类中的实现不可能再被外面调用。new的作用是投影(shadowing),子类隐藏了父类的相同方法,通过强制类型转换外面还可以调用父类的实现。

kingscoming的博客 642

C# 中 类和类中方法的继承关系abstract sealed virtual override 和 new

1、abstract修饰符可以和类、方法、属性、索引器及事件一起使用(待实现)。修饰类时表示抽象类,只能作为其他类的基类,不能被实例化,可以包括抽象方法和抽象访问器,从抽象类派生的非抽象类必须包括继承的所有抽象方法和抽象访问器的实现; 2、sealed不能修饰抽象类,修饰非抽象类时表示该类不能被继承;sealed override可以一起修饰虚方法或虚属性,不可单独修饰虚方法或虚属性; ...

yxt99的博客 350

(十三)sealed、new、virtual、abstract 和 override

一、sealed  密封类不能被继承,密封方法可以重写基类中的方法,但本身不能在任何子类中进行重写。 当应用于方法和属性时,必须始终和override一起使用 。 二、new 显示隐藏从基类继承的成员,不使用new 也是允许的,但会有警告。 三、virtual 修饰的方法和属性被称为虚成员,默认情况下方法是非虚拟的,非虚方法不能重写。 1.静态属性上不可使用 virtual 2.

dxh_0829的专栏 735

c#中abstract、override、new、virtual、sealed使用和示例

abstract      修饰类名为抽象类,修饰方法为抽象方法。如果一个类为抽象类,则这个类智能是其他某个类的基类。抽象方法在抽象类中没有函数体。抽象类中的抽象方法是没有方法体的,继承其的子类必须实现抽象类的抽象方法。      抽象类有如下特征: 抽象类不能实例化抽象类的派生类必须实现所有抽象方法 抽象类中的抽象方法是没有方法体的,继承其的子类必须实现抽象类的抽象方法

richerg85的专栏 1万+
上一篇: 最好的HTML 5编码教程和参考手册分享 .
下一篇: Js offsetTop、offsetParent...
ArvinStudy
博客等级 码龄15年 83粉丝 193原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值