+ 13
*I need HELP!!! ,in Java
public class OverLoad { public int area(int length,int width) { return length*width; } public float area(float radius) { return 3.14*radius*radius; } } public class Program { public static void main(String[] a) { OverLoad obj = new OverLoad(); System.out.println(obj.area(10,8)); System.out.println(obj.area(10.0)); }} continue...
9 Antworten
+ 15
Add f after your float values:
return 3.14f*radiis*radius;
System.out.println(obj.area(10.0f));
Without f these values are doubles and you are doing that bad downcasting thing ^^
+ 12
Yes, float: 32-bit, double: 64-bit.
That's why it is called double. Double of float.
+ 12
It's the same in C++.
[Edit]
But may not cause an error, just messes up because of rounding if you don't take care of it in some cases. But one of the experts could explain that better, for C++ is been a while for me.
+ 11
I have created a simple method overloading program. In the output :
80
error in that place
I don't understand, why this is happening?
+ 11
OK I'll try.
+ 11
wow, thanks Trisha💐 now it's working.
+ 11
Are double and float treated as seperate in Java?I'm asking it because in C or C++ double is just the extension of float.
+ 3
9
+ 2
I think you can use Math.PI for a more precise measurement not sure if it's a float or a double though