Java OCA OCP Practice Question 1335

Question

Which of the following is the best reason for creating a default interface method?

  • A. Allow interface methods to be inherited.
  • B. Add backward compatibility to existing interfaces.
  • C. Give an interface the ability to create concrete methods.
  • D. Allow an interface to define a method at the class level.


B.

Note

The primary motivation for adding default interface methods to Java was for backward compatibility.

These methods allow us to update older classes with a newer version of an interface without breaking functionality in the existing classes.

Option B is the correct answer.

Option is A is nonsensical and not the correct answer.

Options C and D could be accomplished with static interface methods alone.




PreviousNext

Related