Java OCA OCP Practice Question 1626

Question

Given the following pairs of method declarations, which statements are true?.

void m(int distance) {}
int  m(int time, int speed) { return time*speed; }

void m1(int time) {}
int  m1(int distance) { return distance; }

void m3(int time) {}
void M3(int time) {}

Select the two correct answers.

  • (a) The first pair of methods will compile, and overload the method name m.
  • (b) The second pair of methods will compile, and overload the method name m1.
  • (c) The third pair of methods will compile, and overload the method name m3.
  • (d) The second pair of methods will not compile.
  • (e) The third pair of methods will not compile.


(a) and (d)

Note

The first and the third pairs of methods will compile.

The second pair of methods will not compile, since their method signatures do not differ.

The compiler has no way of differentiating between the two methods.

Note that the return type and the names of the parameters are not a part of the method signatures.

Both methods in the first pair are named m and, therefore, overload this method name.

The methods in the last pair do not overload the method name m3, since only one method has that name.

The method named M3 is distinct from the method named m3, as identifiers are case-sensitive in Java.




PreviousNext

Related