Overloaded Methods
a. Method add (…) is overloaded as follows:
static double add( int a, double b) static double add(double a, int b){ { return a + b; return a − b;} }Which, if any, of the following invocations fail to compile? Give reasons.
i. add(1,2)
ii. add(1.0,2.0)
iii. add(1.0, 2)
iv. add(2.0,2)
b. Method sub(…) is overloaded as follows:
int sub( int a, int b) double add(double a, double b){ { return a − b; return a − b;} }Which, if any, of the following invocations fail to compile? Give reasons.
i. sub(1,2)
ii. sub(1.0,2.0)
iii. sub(1.0, 2)
iv. sub(2.0,2)
c. What is the problem with the following overloaded method that returns a product as either an int or a long ?
int mul(int a, int b) long mul(int a, int b){ { return a * b; return a * b;} }
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.