Java OCA OCP Practice Question 3253

Question

Which method declarations, when inserted at (1), will not cause the program to fail during compilation?

public class Main {
  public long sum(long a, long b) { return a + b; }

  // (1) INSERT CODE HERE.

}

Select the two correct answers.

  • (a) public int sum(int a, int b) { return a + b; }
  • (b) public int sum(long a, long b) { return 0; }
  • (c) abstract int sum();
  • (d) private long sum(long a, long b) { return a + b; }
  • (e) public long sum(long a, int b) { return a + b; }


(a) and (e)

Note

Declaration (b) fails, since the method signature only differs in the return type.

Declaration (c) fails, since it tries to declare an abstract method in a non-abstract class.

Declaration (d) fails, since its signature is identical to the existing method.




PreviousNext

Related