Question

The following Java code attempts to demonstrate method overloading, but it has a compilation error. How should it be corrected? public class Calculator {     public int add(int a, int
b) {         return a + b;     }     public double add(int x, int
y) { // Problematic         return x + y;     }     public static void main(String[] args) {         Calculator calc = new Calculator();         System.out.println(calc.add(5, 10));     } }

A Change the return type of the second `add` method to `int`.
B Change the parameter types of the second `add` method (e.g., `double x, double y`).
C Remove the `public` keyword from the second `add` method.
D Rename the second `add` method.
E Add `@Override` annotation to the second `add` method.
Practice Next

Hey! Ask a query