首页 > 其他 > 详细

【转载】Polymorphism

时间:2014-03-12 02:29:43      阅读:480      评论:0      收藏:0      [点我收藏+]

Recall that polymorphism is one of the three core principles of object-oriented programming.

Polymorphism is the idea that the same code can act differently, depending on the underlying type of the object being acted upon. The type of the object is determined at run-time, rather than at compile-time.

In C#, you can use a variable declared as a base type to refer to instances of one or more derived types. Polymorphism allows you to call a method that exist in the base type but whose implementation exists in the derived types. The appropriate method in the derived type will be called, based on the type of the object.

bubuko.com,布布扣
1 Dog d;
2 
3 d = new Terrier("Jack", 15);
4 d.Bark();    // Terrier.Bark is called
5 
6 d = new Shepherd("kirby", 12);
7 d.Bark();    // Shepherd.Bark is called
bubuko.com,布布扣

【转载】Polymorphism,布布扣,bubuko.com

【转载】Polymorphism

原文:http://www.cnblogs.com/yuthreestone/p/3594857.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!