考虑这个代码段
class StockServer {
StockServer(String company, int Shares,double currentPrice, double cashOnHand) {}
double buy(int numberOfShares, double pricePerShare) {
System.out.println("buy(int,double)");
return 3.0;
}
float buy(long numberOfShares, double pricePerShare) {
System.out.println("buy(long,double)");
return 3.0f;
}
}
如果我执行这行代码,
StockServer a = new StockServer("",2,2.0,2);
byte b=5;
a.buy(b,2);
结果将是:购买(int,double)
我想知道编译器如何决定执行哪个方法?