Recall & Review
beginner
What is a default method in Java interfaces?
A default method is a method defined in an interface with a body. It allows interfaces to have method implementations without breaking existing classes that implement the interface.
Click to reveal answer
beginner
How do you declare a default method in a Java interface?
Use the
default keyword before the method name in the interface. For example:<br>default void sayHello() { System.out.println("Hello"); }Click to reveal answer
intermediate
Why were default methods introduced in Java 8?
They were introduced to allow adding new methods to interfaces without breaking existing implementations. This helps evolve interfaces over time.
Click to reveal answer
beginner
Can a class override a default method from an interface?Yes, a class that implements the interface can provide its own implementation of the default method, overriding the interface's version.Click to reveal answer
intermediate
What happens if two interfaces provide default methods with the same signature and a class implements both?The class must override the conflicting default method to resolve the ambiguity, otherwise the code will not compile.Click to reveal answer
Which keyword is used to declare a default method in a Java interface?
✗ Incorrect
The
default keyword is used to declare a method with a body inside an interface.What is the main benefit of default methods in interfaces?
✗ Incorrect
Default methods let interfaces add new methods with implementations without breaking existing code.
If a class implements two interfaces with the same default method signature, what must it do?
✗ Incorrect
The class must override the conflicting default method to avoid ambiguity.
Can default methods call other methods inside the interface?
✗ Incorrect
Default methods can call other methods declared in the interface.
Which Java version introduced default methods?
✗ Incorrect
Default methods were introduced in Java 8 to enhance interfaces.
Explain what default methods are and why they are useful in Java interfaces.
Think about how interfaces evolved to add new features without breaking old code.
You got /4 concepts.
Describe how Java handles conflicts when a class implements two interfaces with the same default method.
Consider what happens when two parents give the same instruction.
You got /4 concepts.