from:http://blog.csdn.net/lzhang007/article/details/7960950html
一 java
overload:是重载的意思,这没啥能混淆的了,就是在同一个类当中,为了增长通用性,写了不少方法,这些方法只有一个要求,参数的数量和类型不一样,但返回值和方法属性必须相同,不然不属于重载,oracle
好比:1.public class Parent{less
public int add(int a, int b){}ide
public int add(int a,float b){}post
public int add(int a,int b,float c){}spa
以上均属于overload .net
protected int add(int a,float b){}翻译
public float add(int a,float b){} }(注意:java中明确声明在同一个类中两个方法名字和参数相同而返回值不一样是不被容许的)code
public class Child extends Parent{
public int add(int a,float b){}(这种在The Java™ Tutorial Fourth Edition中也称做overload可是跟superclass中的同名方法是两种彻底不一样的方法)
}
均不属于overload
参考:http://docs.oracle.com/javase/tutorial/java/javaOO/methods.html
提示:Note: Overloaded methods should be used sparingly, as they can make code much less readable.
它不决定java的多态
二
override有人翻译是重写,有人翻译是覆写,覆盖等。其实我认为是一种扩展
由于它是在父类中声明方法(通常是抽象的),在子类中根据需求去具体定义方法的行为(即modify behavior as needed)
它要求override的方法有相同的名字、相同的参数、相同的返回值类型(即the same name, number and type of parameters, and return type)
它是一种晚绑定,是决定java多态的一种方式
参考:http://docs.oracle.com/javase/tutorial/java/IandI/override.html
三
overwrite:java中就没有它的存在,就别以讹传讹了,java官方文档没有该词的出现,可是国外有人把overwrite解释为override,
好比:http://stackoverflow.com/questions/837864/java-overloading-vs-overwriting
Overriding, which is what I think you mean by "overwriting" is the act of providing a different implementation of a method inherited from a base type, and is basically the point of polymorphism by inheritance, i.e.
public class Bicycle implements Vehicle { public void drive() { ... } } public class Motorcycle extends Bicycle { public void drive() { // Do motorcycle-specific driving here, overriding Bicycle.drive() // (we can still call the base method if it's useful to us here) } }