Java - InterfacesWhat happens if a class implements two interfaces that have the same default method signature?AThe compiler automatically merges both default methods.BThe class must override the default method to resolve the conflict.CThe class inherits both default methods without any error.DThe class inherits the default method from the first interface only.Check Answer
Step-by-Step SolutionSolution:Step 1: Understand multiple inheritance of default methodsWhen two interfaces have the same default method, the implementing class faces a conflict.Step 2: Resolve conflict by overridingThe class must provide its own implementation to avoid ambiguity.Final Answer:The class must override the default method to resolve the conflict. -> Option BQuick Check:Conflict resolution = Override method [OK]Quick Trick: Override conflicting default methods to avoid errors [OK]Common Mistakes:Assuming compiler merges methods automaticallyIgnoring the need to override conflicting 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