//方法重载语法规则
class People{
float hello(int a,int b) //方法,不能用";"
{
return a+b;
}
float hello(long a,int b)
{
return a-b;
}
//float hello(double a,int b)
double hello(double a,int b) //如果此处不改为double,系统会报错"不兼容的类型“,
{
return a*b;
}
float hello(float a,int b)
{
return a/b;
}
}
public class Example4_12{
public static void main(String args[]){
People tom = new People();
System.out.println(tom.hello(10,10));
System.out.println(tom.hello(10L,10));
System.out.println(tom.hello(10.0,10));
//System.out.println(tom.hello(10,10));
}
}
输出内容为:
20.0
0.0
100.0