Static Methods vs Default Methods: Key Differences
You'll learn: How static and default methods in interfaces differ fundamentally in inheritance and purpose.
The Core Distinction
Both static and default methods can have bodies inside interfaces, but they serve entirely different roles:
Default methods are inherited by implementing classes. They provide a default implementation that subclasses can override or use as-is. They're instance methods that work with the object's behavior.
Static methods belong to the interface itself and are not inherited at all. They're utility methods associated with the interface type, called directly on the interface name.
Think of It This Way
Imagine an interface as a job contract:
- Default methods are like "standard procedures" that every employee inherits and can customize if needed.
- Static methods are like "company-wide utilities" in the employee handbook—useful, but not part of any individual employee's personal toolkit.
Key Differences at a Glance
| Aspect | Default Methods | Static Methods |
|---|---|---|
| Inheritance | Inherited by classes | NOT inherited |
| Overriding | Can be overridden | Cannot be overridden |
| Access | Through object instance | Through interface name only |
| Purpose | Extend behavior of implementations | Provide helper/utility methods |
| Polymorphism | Participates in dynamic dispatch | No polymorphism—resolved at compile-time |
Why This Matters
When you implement an interface, its default methods become part of your class's API. Static methods don't—they remain tied to the interface itself. You can't call a static interface method through an instance variable, even if that instance's class implements the interface.
Key Takeaway: Default methods are inherited and can be overridden; static methods are not inherited and serve as interface-scoped utilities independent of implementing classes.