Implementing polymorphic add functions

Report a typo

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.

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