0

What happens if you overload a method without having an alternate?

eg public void do () { system.out.println ("A"); } public void do (int X) { system.out.println (X); } but when u call the method you use another type, like a double? Double dbl =3.655 do (dbl) excuse syntax errors.

27th Mar 2016, 8:08 AM
Jeffery Smith
Jeffery Smith - avatar
2 Respostas
+ 1
This program won't compile properly. The Java Virtual Machine (JVM) checks to determine if method caller parameters match the called method's parameters. In your example, you want do( double parameter) to call do( integer parameter) method. JVM will provide an error concerning improper parameter types.
23rd Apr 2016, 10:19 AM
ic01010101 ◼️LM
ic01010101 ◼️LM - avatar
+ 1
As it010101 wrote, you need to add new overloaded method public void do (double X) { system.out.println (X); }
8th Jul 2016, 10:22 AM
Александр Малин
Александр Малин - avatar