----------------解决方案--------------------------------------------------------
不是。
----------------解决方案--------------------------------------------------------
那该怎样理解?高手指点!说的清楚一点!
----------------解决方案--------------------------------------------------------
重载是指同一个方法(函数)名有不同的参数形式。比如
int max(int a,int b){
return a>b?a:b;
}
int max(int a,int b,int c){
return max(max(a,b),c);
}
这并没有表现出多态性。
注意Overload与Override(覆写)的区别。
----------------解决方案--------------------------------------------------------
那多态从那地方体现出来?
----------------解决方案--------------------------------------------------------
多态.即一种消息多中表现
重载 是多态的静态体现,因为他一中调用方法通过不同的(参数签名)可以得到多种体现
重写 多态的动态体现,这也是java中动态绑定的体现,调用一个方法是在运行时刻才确定调用的是哪个方法
----------------解决方案--------------------------------------------------------
多态在Thinking in Java中是这样说的:
You’ve seen in this chapter that it’s impossible to understand, or even create, an example of polymorphism without using data abstraction and inheritance. Polymorphism is a feature that cannot be viewed in isolation (like a switch statement can, for example), but instead works only in concert, as part of a “big picture” of class relationships. People are often confused by other, non-object-oriented features of Java, like method overloading, which are sometimes presented as object-oriented. Don’t be fooled: If it isn’t late binding, it isn’t polymorphism.
----------------解决方案--------------------------------------------------------
晕!!!!!!!!!!!!!!!
----------------解决方案--------------------------------------------------------
我大概翻译一下:
要想理解多态性,首先要理解数据抽象与继承。多态性是一种不能孤立对待的特性,而只有放在类的继承关系图下才有意义。人们经常会它与JAVA里面那些非面向对象的特性相混淆,比如方法的重载,它常常会被误解为面向对象的特性。不要被欺骗了:不是动态绑定的,就不是多态!
----------------解决方案--------------------------------------------------------
楼主还是找本基础一点的书好好看看吧。
----------------解决方案--------------------------------------------------------