The third principle of object orientation is polymorphism. The dictionary defines it as the occurrence of different forms, stages, or types. Polymorphism means having many forms or implementations of a particular functionality. As with inheritance, polymorphism can be seen in the natural world. Given the command, or function, of "Speak!" a human may reply, "How do you do?" The dog may reply "Woof!" The cat may reply "Meow!" but will probably just ignore you. 练练你的英文吧,看这个.
面向对象三个特性:封装、继承、多态。
封装,就是通过定义类并且给类的属性和方法加上访问控制来抽象事物的本质特性。
继承,就是代码重用。
多态,从另外一个角度分割了接口和实现,即把“什么”和“如何”两个概念分离开来。
As with inheritance, polymorphism can be seen in the natural world. Given the command, or function, of "Speak!" a human may reply, "How do you do?" The dog may reply "Woof!" The cat may reply "Meow!" but will probably just ignore you.
练练你的英文吧,看这个.
加入方法就叫method,
可以有不同的实现,
void method(int p1){}
void method(int p1, double p2){}
void method(double pw, char p3){}
书上有个形象的比喻的,我一下子想不利落了,呵呵。不知道对不对。
那是重载吧-_-