不能,因为调用时不能确定函数返回的类型信息,编译器不知道你要调用哪个函数。
例如:如下代码
package Test;
/**
* 方法的重载代码
*
* 下面以count方法演示代码的重载
*
* @author 宁小菜
*
*/
public class test {public int count(int a,int b) {
return a+b;
}
public int count(double a,int b) {
return (int)a+b;
}
public int count(double a,double b) {
return (int) ((int)a+b);
}
}
当调用count(1, 2);时无法确定调用的是哪个,单从这一点上来说,仅返回值类型不同的重载是不应该允许的。