码迷,mamicode.com
首页 > 其他好文 > 详细

Interview Q&A - 什么是多态?

时间:2014-10-10 14:05:54      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:多态   polymorphism   

Polymorphism is often referred to as the third pillar of object-oriented programming, after encapsulation and inheritance. It has two distinct aspects:

  • At run time, objects of a derived class may be treated as objects of a base class in places such as method parameters and collections or arrays. When this occurs, the object‘s declared type is no longer identical to its run-time type.

  • Base classes may define and implement virtual methods, and derived classes can override them, which means they provide their own definition and implementation. At run-time, when client code calls the method, the CLR looks up the run-time type of the object, and invokes that override of the virtual method. Thus in your source code you can call a method on a base class, and cause a derived class‘s version of the method to be executed. Virtual methods enable you to work with groups of related objects in a uniform way.

Interview Q&A - 什么是多态?

标签:多态   polymorphism   

原文地址:http://blog.csdn.net/troubleshooter/article/details/39959195

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!