public class ChongZai {
void f(float x)
{
System.out.println("float");
}
void f(long x)
{
System.out.println("long");
}
void f(double x)
{
System.out.println("double");
}
void f1(float x)
{
System.out.println("float");
}
void f1(double x)
{
System.out.println("double");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ChongZai cz=new ChongZai();
cz.f(5);
cz.f1(5);
}
}
void f(float x)
{
System.out.println("float");
}
void f(long x)
{
System.out.println("long");
}
void f(double x)
{
System.out.println("double");
}
void f1(float x)
{
System.out.println("float");
}
void f1(double x)
{
System.out.println("double");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ChongZai cz=new ChongZai();
cz.f(5);
cz.f1(5);
}
}
取值范围大的排后面呗!
对象排最后,因为java5以后才支持自动拆包
void f(int x) {
System.out.println("int");
} void f(long x) {
System.out.println("long");
} void f(float x) {
System.out.println("float");
} void f(double x) {
System.out.println("double");
} void f(Integer x) {
System.out.println("Integer");
} void f(Number x) {
System.out.println("Integer");
} public static void main(String[] args) {
// TODO Auto-generated method stub
T2 cz = new T2();
cz.f(5);
}从上到下,依次注释掉方法void f(int x) 、void f(long x) .......
然后运行,结果是:
注释掉void f(int x) 就调用void f(long x)
再注释掉void f(long x) 就调用void f(float x)
......
Number是Integer的super