Incomplete Implementation: Compiler Errors
What You'll Learn
You'll learn why Java refuses to compile a concrete class that doesn't implement all methods from its interface, and what your options are to fix it.
The Compiler's Strict Contract Enforcement
When a class declares that it implements an interface, it's making a promise: "I will provide concrete implementations for every single method in that interface." Java takes this promise seriously. If your class fails to implement even one interface method, the compiler immediately throws an error and refuses to compile your code.
Think of it like signing a business contract. If you agree to deliver five services but only provide four, you haven't fulfilled your contract. Java won't let you get away with partial implementation.
What Triggers the Error
This happens when:
- You use the
implementskeyword with an interface - You forget to implement one or more interface methods
- You misspell a method name or get the signature wrong (parameters, return type)
Your Two Options
Option 1: Implement all methods
Complete the contract by adding implementations for every missing method. This is what you'll do most of the time.
Option 2: Declare your class abstract
If you can't or don't want to implement all methods yet, you can mark your class as abstract. This defers the implementation responsibility to future subclasses. An abstract class isn't required to implement interface methods—it passes that obligation down the inheritance chain.
The Compiler Message
Java's error message is clear: it tells you exactly which methods are missing and which interface they come from. Pay attention to these messages—they guide you to the solution.
Key Takeaway:
A concrete (non-abstract) class must implement every method from every interface it claims to implement, or the code won't compile—there's no middle ground.