Java OCA OCP Practice Question 1477

Question

An overriding method must have a same parameter list and the same return type as that of the overridden method.

Select 1 option

  • A. True
  • B. False


Correct Option is  : B

Note

This would have been true prior to Java 1.5.

From Java 1.5, an overriding method is allowed to change the return type to any subclass of the original return type, also known as covariant return type.

This does not apply to primitives.

For primitives, the return type of the overriding method must match exactly to the return type of the overridden method.




PreviousNext

Related