#멋쟁이사자처럼 #부트캠프 #백엔드 #JAVA
실습 문제
Interfaces
- Can only contain abstract methods.
- However, since Java 8,
default and static methods are also allowed.
- Can include
public static final constants.
- Supports multiple implementations.
- A single class can implement multiple interfaces.
- Provides looser coupling compared to inheritance and offers a standardized way of use.
public class MyClass implements InterfaceA, InterfaceB, InterfaceC {
// ...
}
Interface Fields
Fields in a Java interface are implicitly public static final by default.
default Methods
- Methods in an interface that contain implementation code.
- Provide a default implementation that all implementing classes can use.
- Can be overridden in the implementing class if needed.
- Enable adding new methods to an interface without breaking existing code.
Gemini: Default Methods