Bird
0
0

What is the main purpose of default methods in Java interfaces?

easy📝 Conceptual Q11 of 15
Java - Interfaces
What is the main purpose of default methods in Java interfaces?
ATo enable multiple inheritance of classes
BTo declare abstract methods that must be implemented by classes
CTo create private helper methods inside interfaces
DTo allow interfaces to have method bodies without breaking existing implementations
Step-by-Step Solution
Solution:
  1. Step 1: Understand interface method rules before Java 8

    Interfaces could only declare abstract methods without bodies, forcing all implementing classes to define them.
  2. Step 2: Role of default methods

    Default methods allow interfaces to provide method bodies, so new methods can be added without breaking existing classes.
  3. Final Answer:

    To allow interfaces to have method bodies without breaking existing implementations -> Option D
  4. Quick 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 methods
  • Thinking default methods enable multiple inheritance of classes
  • Believing default methods are private helper methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes