Skip to content
Advertisement

how do i settle this overloading java

how to calculate 2 number integer and float by using overloading in java

JavaScript

this is my code but i still get both of them is float

Advertisement

Answer

You define your a and b variables as float, so Java selects the method that has parameters of type float, because, in addition to a method name, Java uses parameter types to differentiate between methods. See more here.

Try to rewrite your code as:

JavaScript

UPD: Also, as Dawood ibn Kareem correctly mentioned in the comment, you need to change the return type of the first HasilDarab method to int.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement