最近学习c#,昨晚看书看到多态。由于个人本身是从事java开发,于是拿来做对比便是自然的。

进入主题吧。

c#中,子类要重写基类的方法,必须要基类声明中带有virtual关键字方法或者带有abstract关键字的抽象方法,然后子类中重写该方法时使用override关键字。

例如:

 class A
{
private String name;
public String Name
{
get
{
return name;
}
set
{
name = value;
}
} public A(String name)
{
this.name = name;
} public virtual String Test()
{
return name;
}
} class B : A
{
private int age;
public B(String name,int age)
: base(name)
{
this.age = age;
}
public override string Test()
{
return this.Name + ":" + age;
}
}

对于带有关键字abstract的抽象方法,子类中必须要重写,这与java中都是一样的。
但是在java中,子类重写基类的普通方法,只需要与父类的方法声明一致,就会重写父类的方法。

重写之后,在多态上的表现便会和大家期望的一致,调用子类重写的方法,而不再是调用父类的方法了。

 static void Main()
{
A c1 = new A("Tom");
System.Console.WriteLine( c1.Test());
A c2 = new B("Jerry",);
System.Console.WriteLine(c2.Test());
}

会发现后台输出的是aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJIAAAAkCAIAAADtivSxAAADI0lEQVRoge2b61qiQBiAvaw9tR3c3dyuMUp7RBRFgfnmwGmge7CyFEyvZH9gPa0cJLc1yHmf7wd8wDDO64wwSG1A0ICgPo7DfIjC+lmj9kqCIEhmsnht4duRdaIiFfiXY3fEgMDKHNlem2DX9GNhBPUJUrF5L7RVgpUzjFRsxtpOfgttpaePkQqoB6gHpgpCW0Xomug5FMOczMKj08Z7XUcIitLVkaIjZYQ6I9QZmZNpePirEXt6Fia0lQ5ZA1mDtgbtAbQ1dDsND36sBknRz8pLS4WWCq0etFRo9tDNffjtJE9b6sgpBtVdc9mBi1Wgiw4aT8IvR5naXmZSl9dGV8H/4kIGSQapjSQZSTIa34WfvwttpUdqg9SG86cY30WfDoS20iPJWGpjqQ3nMkgyjO8i0dsqQFPBlx3c7OCmgi8VuJlE8W9b1vVFaj5/VfD2XPXwKlS4UuH2Pvp6LGZJSo88xPIQy0OQNZCHcDcND+pCW+lRDKIYpGtgRcddA09m0eFPoa309IEMgPQBx/EQRkenQlvp0Qh5jgHBD/PouCG0lZ4ho0NGNUY0hjWGp/NIPLipALpFdYvoFhkxMmJkOo/qQlv50R0ax8imI5tOH+cv/5SQdfe2e4rcR757JXeH4TDDpnHoFpn9ra1WjnvnjbMzqasfGcNmT0F1i5ZBW/4sTP7yvmgzHct0mOlQ06GGs1lbzuRWkJiQzMqn7pZaWpLUA1Nr9ZExXct0LcNhccwWedo2tnUt0egb88micsg56avKqTzIs5BrmS4zXWY6LFzM62eN/PZN/Wq/zKQekppPLueQ3G2tJnukDTwbPBu5VhxFtKWWk7WpSD7nG5Bfztqee6cNPBt5NnLtcPFYUFtqWyfL32g6pw+lFrJFHT4gmNuYO8Bt4DZ4K221rZ63Fdx5jSJtHSTI2lTsQ1cf7DvAHcwd7DnYs6Pl4y7fAdivtn5DiO9i38XcwdwGviNt+9g/3hYaeCtzvou5Ey0X4o2bCsACTn2P+h7xPeJ7Qls1YNecBpwGnPic+F60XAptFYBdcxZwFnAaeCTg8+VSPLgpP38A4PSllwNe2kQAAAAASUVORK5CYII=" alt="" />

到这里,除了写法上比java多了两个关键字,其他都是一样的,很好理解。但是在使用new隐藏父类方法的时候,就稍微有点晕了。

 class C : A
{
public String Code { set; get; }
public C(String name)
: base(name)
{
this.Code = "";
} public new String Test()
{
return this.Name + ":" + this.Code;
} }

如上,使用new关键字隐藏父类的Test方法,这里,隐藏父类方法,不像重写那么严格,关键字可以与父类不同,甚至连返回类型也可以不同,但是方法名和参数必须一致。

运行代码

 static void Main()
{
System.Console.WriteLine("这是main方法");
A c1 = new A("Tom");
System.Console.WriteLine( c1.Test());
B c2 = new B("Jerry",);
System.Console.WriteLine(c2.Test());
C c3 = new C("Anlex");
System.Console.WriteLine(c3.Test());
}

会发现结果aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANQAAAB2CAIAAAA/aCqqAAAYzElEQVR4nO2deXva2KGH/bHuZPOW2GQ+SXt725nOZHUcL/GOMTuIVaxCIAkht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cjZHN3Z3N3e3N3++8//QTkA7SD6t7u1t5uQ8Gt3R0gH6BNbB/sbe/vVff3qvu71f3d6t7uP34G8gHaws7h/s7h/s7B/s7B/vbB3vbB3k8//wzkA7SD3dcHu4dCahb+9AuQD9AW9o9e7x8d7h0d7r2u5adffwHyAdrB/tHreg73jw73Xh/+DOQDtIeD46OD46OD49f7xzULgXyANnH45khIw8Jffv0VyAdoB6/fHr9+c3xYy9Hhm6Nf/gnkA7SFo7dvhLyu5RjIB2gTRydvj07eHJ289+/Xf/4TyAdoB8fvTo5P3h6fvD2q59d/AfkAbeHNu5OGf0KAfIA28ebdiZDjdyfH74B8gDby5od3b3549+aH9wr++q9/AfkA7WDv1Lk14STvT7/8Au7PB2gH/kiICoeocNDHB318kAwFdg8PwZ1JAe1AYTErYJPcbJSZjTKTQWYyLK2tAvkA7UBqMMwZDBK9XqLTzep0YggqVSrdIiAf4OaZ1RnEkF4M6Wa0uhktNK2BCuVKVz+QD3DzTGv0U2rdlFo3qYImlNCEElpcqXT2AfkAN8+4Qj8u143JoTE59EoGjUq1C0uVe/eBfICbZ0SiG5XoRmah4VloeFY7PKvNl8p3e4F8gJtncFo3OA0NTkMvp7Uvp7WDM5p8sXynB8gHuHmejUPPx6HnE9rnk9qBSc3ApCZXKN/uBvIBbp4no9DTV9CzMe2zMc2zcc3zcU12sXyrC8gHuHmejEBPRrRPRjVPXmmevtI8HVMD+QBt4vGw9vGo9smo5smo5umY+tmYOrO4AuQDtIH/B8rTJYiuPSrSAAAAAElFTkSuQmCC" alt="" />,与之前重写父类方法得到的效果一致,于是不太明白new到底做了什么用。

但是细心的朋友们一定注意到了,这里给大家埋了一个坑,运行的代码里,都是定义了自己的对象,运行自己的方法,结果自然会是如此了,根本就没有体现出多态。

如果这里是定义父类的变量,去指向子类的实体的话。

static void Main()
{
System.Console.WriteLine("这是main方法");
A c1 = new A("Tom");
System.Console.WriteLine( c1.Test());
A c2 = new B("Jerry",);
System.Console.WriteLine(c2.Test());
A c3 = new C("Anlex");
System.Console.WriteLine(c3.Test());
System.Console.ReadLine(); }

结果便是:aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANcAAAB6CAIAAACjnVHSAAAgAElEQVR4nO2d6XMaaZ7nH/6pnZmeLluyLGTXXdMTs9uxMbER+2ar7Kpy2ZY9ERu7sdE9XVU+5UO3hJAEQtx3Agl5kweQQJKAbiTLki9VlSRAR1muerMvnkyETh9dlt3t/MYniCR5MkmUH35PPo9AAuVyxe0LenyI1x/yBkLeQMgbDPuCEV8wQse5qZkHVwbIq4PEtWH8+gh20xqbmLi3urK8uLCwuLCwsrLc50/3+dMYyTjcXorhGJZn+QSfSAmpdDKdjdxtBs3t0Zws5fK5fCFXKMqFouOyDlxyyYXiDvJ7Kcj5guy8rAOX7fliDkJ06YG+nSjkZIirVQcuOgoS3tUM9O14QZILklyQcnlIth77JR1otap3pVw+K+clGd6qO8zXU4QLtUfhzrNyISu7LurARUc+i3U2A/1dLJ/N5TNYRzMAF2xyRpIzWTmdzdUjZqRt0lkxnU2ls6l0NilmkulMUswkxUxCzCTEdCKVFlJpIZkWkqKQFPmEyCdSnJDkTN/owDkjn2A4geEEmuXpOE8xHMVwJM2SNEvScYKK41Qcp5gdkAxGMhhJb9N3VgfO9hB0jKBjOLWLqMqOuxh5EGiMQGNEJIZHYngkikeiGBrDYziJkzRJMxTD0nGOiXMMyzEc77txAjTe8HJ8nOUZlqfjHB3nQLlc8QTqFAyEfIGQLxj2BsM0w06XHn/eFvjirv/LHs/XA67zJkc+X1pd/rHewoFICiMZh9tDM2zNwkQqnVIs7EBzsiTnc/mCXCjmi2OOyzpw2S0XxxTyu9gWMZcv2i/pQKsrp1qIdbYAfReWL+bkYk4u5hyXdeCSXS7kdlko5yU5X++ilMvbWnXgokNZKe+8VUWU5ELtuXJyMScXcnJR2lYwr+zfcVkHWm25vKRYKEOzrRd14KIjI0ERcxlJVTAriVlJzEipGmkplc6mxGxSzEIFFQtTaYiQEqGFQkLkEyleSEELB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0tf/SxZqGWo8rW1tbMzNz0zOw0vJ2enZqeXV0tf6D9FU0tR5anW1vTM3NT05BZyMpq+dTpo/u71lre9Tx9ujU5PTc5NTtRY3J2eaWsfftJy9Hl6dOtyam58am58anZ8UlIaXml3NT8wZs+NC3vTJ4+3ZqAFioKzo5Nzi6vlBuatM/UaDmqKBZOKoxNzo5NzC6vlLXv4Gk5ujzdejY5PT8xdQ8yPjU3Pjm3vFJ+r0GzUMtR5enWs6mZ+cnpexPT0MJ741Nzyyvl32uftdZyZHm69Wy6dH9qZn5yZn5yWtFxZbWifeJfy9Fla+vZzOzCzOzC9Oz96dL96dL9qZn7q6tVrUfWcnTZevZsbv7B7L3F2XuLpbkFyGq52qB970TLkeXZs1/uLzych9x/cG/+wb35B5XK2olm7XsnWo4qz579svjg0eKDR4uLjxYWHy0sPry/+KhaXde+d6Ll6PLLL788evTkocLjhw8fP3j4eG1tXfveiZajyy+//PL4ydLjJ0uPHy89evzk0eOlR4+frK9vfKh9pkbLkeWXX35dWvoB8kRhaWNjU/veiZajy6+//vrDDz/+8MMPS5ClH5aWftjY2NT+G6OWo8uzZ788ePBwcZsHi4sPqmtrmoVaji5ra+sEGcdJpgZBxhcXH3ys/ZduLUeW5eUV47BtYMhqGBo1DlqNQ6PGIev4xJQ2OtFydPnxx+WOHlN711B711B7z1BHz1Bn73C+OK7N1Gg5uiz98NP1OwPXbg9cu2W4fmfg5h1D212DlBvTn9JmrbUcUf4/h3mj4KTQe8MAAAAASUVORK5CYII=" alt="" />

这时,c2.Test()是调用了子类重写的方法,而c3.Test()是调用了父类的方法,并不会调用类C里的Test()方法。

到这里,我想大家都理解隐藏的意思了吧。也明白书上一直强调的,要慎用new关键字隐藏父类方法了吧。

c#中override重写和new隐藏的更多相关文章

  1. c#中的重写方法与隐藏方

    1.父类中有方法a,添加virtua修饰符可声明为虚方法,在子类中可以用override声明后重写方法a. 2.父类中有方法a,在子类中可以有new修饰符声明后隐藏父类方法. 子类重写方法后,对于子类 ...

  2. C# 读书笔记之访问虚方法、重写方法和隐藏方法

    C#允许派生类中的方法与基类中方法具有相同的签名:基类中使用关键字virtual定义虚方法:然后派生类中使用关键字override来重写方法,或使用关键字new来覆盖方法(隐藏方法). 重写方法用相同 ...

  3. C#override与new修饰隐藏的区别(转载)

    C#比java多一个new隐藏的功能.C# override重写相当于java中没有关键字的方法重写.所以java中方法是没有隐藏功能的. C# override重写,是指对父类中的虚方法(标记vir ...

  4. C#中override和overload的区别

    重载应该叫overload,重写叫override:重载某个方法是在同一个类中发生的!重写是在子类中重写父类中的方法. 1.override:   父类:public virtual string T ...

  5. java中的重写与重载

    重写(Override) 重写是子类对父类的允许访问的方法的实现过程进行重新编写, 返回值和形参都不能改变.即外壳不变,核心重写! 重写的好处在于子类可以根据需要,定义特定于自己的行为. 也就是说子类 ...

  6. Java中方法重写和方法重载

     首先方法重写和方法重载是建立在Java的面向对象的继承和多态的特性基础上而出现的.至于面向对象的继承和多态的特性我就不在这里多说了.继承是指在一个父类的基础再创建一个子类,这样子类就拥有了父类的非私 ...

  7. overload(重载) 和 override(重写)的区别

    overload(重载): 重载是基于一个类中,方法名相同,参数列表不同(如果参数列表相同时,参数的类型要不同),与返回值和访问修饰符都无关 如果在面试中就直接说:"同名不同参"  ...

  8. unity3d中让物体显示和隐藏

    unity3d中让物体显示和隐藏的方法 gameObject.renderer.enabled //是控制一个物体是否在屏幕上渲染或显示  而物体实际还是存在的 仅仅是想当于隐身 而物体本身的碰撞体还 ...

  9. 在Form Load中设置showInTaskBar =false 或 隐藏窗口 this.Hide()时会导致注册的全局快捷键无效

    在Form Load中设置showInTaskBar =false   或 隐藏窗口 this.Hide() 会导致注册的全局快捷键无效.  反正是其中一个,有点记不清了. 在Form Shown中s ...

随机推荐

  1. [Head First Python]2. python of comment

    1- 多行注释 ''' ''' 或 """ """ '''this is the standard way to include a mul ...

  2. django中使用json.dumps处理数据时,在前台遇到字符转义的问题

    django后台代码: import json ctx['dormitory_list'] = json.dumps([{", "is_checked": 1}, {&q ...

  3. LinqToSql 小例子

    namespace LinqToSqlDemo.Test { class Program { // 数据连接文本 private static DataClasses1DataContext data ...

  4. sql server 表连接

    本文主要列举两张和三张表来讲述多表连接查询. 新建两张表: 表1:student 截图如下: SQL多表连接查询(详细实例)_新客网 表2:course 截图如下: SQL多表连接查询(详细实例)_新 ...

  5. USB系列之五:用汇编实现的一些USB功能

    前面的USB系列一至四,实现了我们需要的一些USB功能,但都是用C语言的32位代码,之后我们插进了三篇关于DOS下设备驱动程序的文章,我们现在应该清楚,当我们要在DOS下写一个U盘的驱动时,最好使用汇 ...

  6. 8051_asm.uew

    /L20"8051 Assembly" AASM_LANG Line Comment = ; Nocase String Chars = ' File Extensions = S ...

  7. JavaEE Tutorials (28) - Duke书店案例研究示例

    28.1Duke书店的设计和架构43828.2Duke书店接口439 28.2.1Book Java持久化API实体439 28.2.2Duke书店中使用的企业bean440 28.2.3Duke书店 ...

  8. UESTC_菲波拉契数制升级版 2015 UESTC Training for Dynamic Programming<Problem L>

    L - 菲波拉契数制升级版 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Su ...

  9. UESTC_Infected Land 2015 UESTC Training for Search Algorithm & String<Problem G>

    G - Infected Land Time Limit: 6000/3000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others ...

  10. Pattern | CLiPS

    Pattern | CLiPS Pattern Pattern is a web mining module for the Python programming language. It has t ...