In a Java program, there are two methods with the same name 'add', but with different parameter types. These methods perform addition operation and return the result. One method adds two integers, while the other one adds two double values. You need to fill the blanks in the code that makes these two methods work properly so that the program can successfully add two integers as well as two double numbers.
Overloading
Implementing method overloading for addition operation
Report a typo
Fill in the gaps with the relevant elements
public class Main {
add(int a, int b) {
a + b;
}
static add(double a, double b) {
return a + b;
}
public static void main(String[] args) {
System.out.println(String.valueOf(add(2, 3)))
System.out.println(String.valueOf(add(2.0, 3.0)));
}
} ___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.