Java OCA OCP Practice Question 1260

Question

Which of the following statements about overriding a method is incorrect?

  • A. The return types must be covariant.
  • B. The access modifier of the method in the child class must be the same or broader than the method in the superclass.
  • C. A checked exception thrown by the method in the parent class must be thrown by the method in the child class.
  • D. A checked exception thrown by a method in the child class must be the same or narrower than the exception thrown by the method in the parent class.


C.

Note

First, the return types of an overridden method must be covariant.

It is true that the access modifier must be the same or broader in the child method.

Using a narrower access modifier in the child class would not allow the code to compile.

Overridden methods must not throw any new or broader checked exceptions than the method in the superclass.

Options A, B, and D are true statements.

Option C is the false statement.

An overridden method is not required to throw a checked exception defined in the parent class.




PreviousNext

Related