Junior — Middle
Do methods with default implementation exist in interfaces?
sobes.tech AI
Answer from AI
Yes, starting from Java 8, interfaces can contain methods with default implementations, which are declared with the default keyword. This allows adding new methods to interfaces without breaking existing implementations.
Example:
public interface MyInterface {
default void defaultMethod() {
System.out.println("This is a method with a default implementation");
}
}