+ 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...

11th Mar 2017, 12:42 AM
Ajay Agrawal
Ajay Agrawal - avatar
9 Respostas
+ 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 ^^
11th Mar 2017, 1:00 AM
Tashi N
Tashi N - avatar
+ 12
Yes, float: 32-bit, double: 64-bit. That's why it is called double. Double of float.
11th Mar 2017, 1:06 AM
Tashi N
Tashi N - avatar
+ 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.
11th Mar 2017, 1:10 AM
Tashi N
Tashi N - avatar
+ 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?
11th Mar 2017, 12:44 AM
Ajay Agrawal
Ajay Agrawal - avatar
+ 11
OK I'll try.
11th Mar 2017, 1:01 AM
Ajay Agrawal
Ajay Agrawal - avatar
+ 11
wow, thanks Trisha💐 now it's working.
11th Mar 2017, 1:03 AM
Ajay Agrawal
Ajay Agrawal - avatar
+ 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.
11th Mar 2017, 1:04 AM
Ajay Agrawal
Ajay Agrawal - avatar
+ 3
9
11th Mar 2017, 10:08 PM
mohamed benHammou
mohamed benHammou - avatar
+ 2
I think you can use Math.PI for a more precise measurement not sure if it's a float or a double though
11th Mar 2017, 4:43 AM
sniperisdemoman
sniperisdemoman - avatar