Interview Question

What is an interface?

Interfaces define contracts that multiple classes can implement.

💡 Concept ✅ Quick Revision ☕ Java

Answer

An interface defines a reference type whose members can specify contracts and shared default behavior. • A class may implement multiple interfaces. • Interface fields are implicitly public static final. • An interface cannot be instantiated directly.

Example

Code
interface Greeting {
    String message();
}
class Hello implements Greeting {
    public String message() { return "hello"; }
}

Quick Revision

Interfaces define contracts that multiple classes can implement.