当前位置: 代码迷 >> Java相关 >> 关于Java重载
  详细解决方案

关于Java重载

热度:269   发布时间:2007-03-07 19:36:43.0
关于Java重载
Java的多态是不是表现在函数的重载中?
搜索更多相关的解决方案: Java  重载  多态  函数  

----------------解决方案--------------------------------------------------------
不是。
----------------解决方案--------------------------------------------------------
那该怎样理解?高手指点!说的清楚一点!
----------------解决方案--------------------------------------------------------
重载是指同一个方法(函数)名有不同的参数形式。比如
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重载

多态.即一种消息多中表现
重载 是多态的静态体现,因为他一中调用方法通过不同的(参数签名)可以得到多种体现

重写 多态的动态体现,这也是java中动态绑定的体现,调用一个方法是在运行时刻才确定调用的是哪个方法


----------------解决方案--------------------------------------------------------
多态在Thinking in Java中是这样说的:
Polymorphism means “different forms.” In object-oriented programming, you have the same face (the common interface in the base class) and different forms using that face: the different versions of the dynamically bound methods.

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里面那些非面向对象的特性相混淆,比如方法的重载,它常常会被误解为面向对象的特性。不要被欺骗了:不是动态绑定的,就不是多态!

----------------解决方案--------------------------------------------------------
楼主还是找本基础一点的书好好看看吧。
----------------解决方案--------------------------------------------------------
  相关解决方案