Your task is to extend a simple Java program that provides two variations of an 'add' function. One function should add two integers and the other function should add two doubles. These functions should display polymorphic behavior so that the correct 'add' function is called based on the provided arguments. Fill the blanks in the code to correctly declare and implement these functions, ensuring to return the correct data type in each case.
Overloading
Implementing polymorphic add functions
Report a typo
Fill in the gaps with the relevant elements
class Main {
public void main(String[] args) {
System.out.println(add(5, 10));
System.out.println(add(5.5, 10.5));
}
public static int add(int a, int b) {
a + b;
}
public static add(double a, double b) {
return a + b;
}
}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.