Java OCA OCP Practice Question 46

Question

Which of the following may override a method whose signature is void myMethod(float f)?

  • A. void myMethod(float f)
  • B. public void myMethod(float f)
  • C. private void myMethod(float f)
  • D. public int myMethod(float f)
  • E. private int myMethod(float f)


A, B.

Note

A uses the original method's signature verbatim, which is legal.

B makes the subclass version more accessible, which is legal.

C makes the subclass version less accessible, which is not legal.

D and E change the return type, which is not legal.




PreviousNext

Related