Java - InterfacesWhat is the main purpose of default methods in Java interfaces?ATo enable multiple inheritance of classesBTo declare abstract methods that must be implemented by classesCTo create private helper methods inside interfacesDTo allow interfaces to have method bodies without breaking existing implementationsCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand interface method rules before Java 8Interfaces could only declare abstract methods without bodies, forcing all implementing classes to define them.Step 2: Role of default methodsDefault methods allow interfaces to provide method bodies, so new methods can be added without breaking existing classes.Final Answer:To allow interfaces to have method bodies without breaking existing implementations -> Option DQuick Check:Default methods add bodies to interfaces safely [OK]Quick Trick: Default methods add code to interfaces without breaking old classes [OK]Common Mistakes:Confusing default methods with abstract methodsThinking default methods enable multiple inheritance of classesBelieving default methods are private helper methods
Master "Interfaces" in Java9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Java Quizzes Abstraction - Abstract classes - Quiz 12easy Classes and Objects - Instance methods - Quiz 15hard Classes and Objects - Object interaction - Quiz 13medium Classes and Objects - Object interaction - Quiz 5medium Constructors - Default constructor - Quiz 15hard Constructors - This keyword usage - Quiz 11easy Custom Exceptions - Best practices - Quiz 1easy Exception Handling - Checked vs unchecked exceptions - Quiz 4medium Inheritance - Why inheritance is used - Quiz 6medium Interfaces - Static methods in interfaces - Quiz 15hard