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