I tried this method overloading code and I got the error
no suitable method found for add(double,double)
The code:
class Adder {
static float add(float a, float b) {
return a + b;
}
static int add(int a, int b) {
return a + b;
}
}
class TestOverloading1 {
public static void main(String[] args){
System.out.println(Adder.add(11.5, 11.5));
System.out.println(Adder.add(27, 21));
}
}
On writing, 11.5f in params, this works well.
I understood the differences between float and double from here and here.
So, why does Java take the parameters as double datatype by default? Is the higher precision of double behind such a bias?
I am aware that it takes the double by default. But, I wish to know what is the reason behind this?