The implements keyword in Java is used in a class declaration to adopt one or more interfaces. The class must provide a concrete method body for every abstract method the interface defines. Failing to do so causes a compile-time error. A class can implement multiple interfaces simultaneously, separated by commas.
- Key Takeaway 1:
implementsis used by a class to adopt one or more interfaces; a class that fails to define all interface methods must be declaredabstract. - Key Takeaway 2: A single class can implement multiple interfaces at the same time, separated by commas.
- Key Takeaway 3: An interface can extend another interface using
extends, notimplements. - Key Takeaway 4: Java interfaces can carry
defaultmethods (since Java 8), so not every method you inherit needs an override. - Key Takeaway 5: The
@Overrideannotation is optional but strongly recommended; it catches typos in method signatures at compile time.
What the implements Keyword in Java Does
An interface in Java is a pure specification. It lists method signatures (and sometimes constants) but, in its traditional form, provides no implementation. Think of it as a signed agreement between the interface author and every class that claims to follow it.
When a class uses the Java implements keyword, it accepts every obligation in that agreement. The Java compiler then checks, before your program even runs, that every obligation has been met. According to the Oracle Java Documentation, a class that implements an interface must provide implementations for all of the interface’s methods or be declared abstract. This compile-time enforcement is the entire point of object-oriented programming contracts in Java.
The Basic Syntax of implements in Java
| Keyword | Used by | Used with | Allows multiple targets? |
|---|---|---|---|
implements |
Class | Interface(s) | Yes, comma-separated |
extends (class) |
Class | One superclass | No, single inheritance only |
extends (interface) |
Interface | Interface(s) | Yes, comma-separated |
The syntax is always class ClassName implements InterfaceName. If the class also extends a superclass, extends comes first: class ClassName extends SuperClass implements InterfaceName. Getting that order wrong is a common beginner mistake that produces an immediate compile error.
What Happens at Runtime
At runtime, the implements keyword in Java enables polymorphic behaviour. You can hold a Dog object inside an Animal reference and call any method the Animal interface defines. Java dispatches to Dog‘s actual implementation. This is the core mechanism behind dependency injection frameworks like Spring, which most Indian IT companies use heavily in their backend stacks.
A practical tip from real projects: always code to the interface type in variable declarations (Animal a = new Dog()), not the concrete type. It makes your code far easier to swap and test. Senior developers at product companies will specifically look for this habit during technical interviews.
How to Implement an Interface in Java
Here is a minimal, working example. Suppose you are building a payment gateway module, a common task in fintech projects across Bengaluru and Pune.
You define the contract:
interface PaymentGateway { void processPayment(double amount); boolean refund(String transactionId); }
Then you implement it:
class RazorpayGateway implements PaymentGateway { @Override public void processPayment(double amount) { System.out.println("Processing ₹" + amount + " via Razorpay"); } @Override public boolean refund(String transactionId) { System.out.println("Refunding transaction: " + transactionId); return true; } }
Every method from PaymentGateway appears in RazorpayGateway with the @Override annotation. Drop either method and the compiler throws an error immediately, before the code ever touches a server.
The Role of @Override
@Override is technically optional, but skipping it is a bad habit. If you misspell processPayment as processpayment, Java silently treats it as a brand-new method rather than an override. You end up with an unimplemented interface method and a confusing bug. The annotation forces the compiler to verify the method signature matches, catching the error instantly.
Default Methods and When You Do Not Need to Override
Since Java 8, interfaces can include default methods with a full body. A class using the Java implements keyword inherits that default behaviour automatically and only needs to override it if the default is not suitable. According to the Java 8 Language Enhancements documentation from Oracle, default methods were introduced specifically to allow interfaces to evolve without breaking every existing implementation. That is a significant advantage in large codebases where an interface might be implemented by dozens of classes.
If you are new to compiling Java programs and want to get your environment set up first, the guide on how to write, compile and run a C program gives a solid grounding in the compile-run cycle that applies directly to Java too, since both languages share the same build-before-execute model.
Multiple Interface Implementation in Java
Java does not allow a class to extend more than one class. That is a deliberate design choice to avoid the diamond problem. But a class can implement as many interfaces as it needs, and this is how Java achieves flexible, multi-role object-oriented programming behaviour.
Imagine a SmartDevice class that needs to behave as both a Connectable device and a Printable device:
interface Connectable { void connect(String network); } interface Printable { void print(String document); } class SmartDevice implements Connectable, Printable { @Override public void connect(String network) { System.out.println("Connected to " + network); } @Override public void print(String document) { System.out.println("Printing: " + document); } }
The class lists both interfaces after implements, separated by a comma. It must then fulfil every method from both contracts.
Handling Default Method Conflicts
A conflict arises when two interfaces both define a default method with the same signature. In that case, Java forces the implementing class to override the method and resolve the ambiguity explicitly. You can call a specific interface’s default version using InterfaceName.super.methodName(). Knowing this will set you apart in Java interviews at companies like Infosys, TCS or Wipro.
According to the Stack Overflow Developer Survey 2024, Java is used by 30.3% of professional developers worldwide, making it one of the most-used languages in enterprise software. If you are studying for Java interviews as part of an MCA programme, the guide on jobs and salary after MCA is worth reading alongside your Java prep. Strong OOP fundamentals directly influence which roles and pay bands you qualify for. In India, Java developers with solid interface and OOP skills earn between INR 4.5 LPA and INR 12 LPA at entry to mid-level, according to AmbitionBox salary data for 2024.
Common Mistake: Forgetting an Interface’s Methods
When you use the implements keyword in Java with two or three interfaces, it is easy to miss a method from one of them. The compiler will flag it, but the error message lists the missing method signature, not which interface it came from. Always check each interface individually when you get that error. This is exactly the kind of compile-time confusion covered in the article on Java exceptions and common runtime errors.
How an Interface Extends Another Interface in Java
An interface can build on another interface using the extends keyword. This is called interface inheritance, and it lets you create layered contracts without duplicating method declarations.
interface Vehicle { void startEngine(); } interface ElectricVehicle extends Vehicle { void chargeBattery(); }
Any class that implements ElectricVehicle must provide bodies for both startEngine() (inherited from Vehicle) and chargeBattery(). The implementing class inherits the full chain of obligations.
Multiple Interface Inheritance
An interface can extend multiple interfaces at once: interface SmartElectricVehicle extends ElectricVehicle, Connectable. This is one area where Java interfaces are more flexible than classes. According to the TIOBE Index for May 2025, Java holds a 15.16% rating, ranking it among the top three most-used programming languages globally, and interface inheritance is one of the features that keeps it dominant in enterprise systems where contract-based OOP design is non-negotiable.
Java implements vs extends: A Direct Comparison
| Scenario | Correct keyword | Example |
|---|---|---|
| Class adopts an interface | implements |
class Cat implements Animal |
| Class inherits from another class | extends |
class Kitten extends Cat |
| Interface inherits from another interface | extends |
interface Pet extends Animal |
| Class inherits class AND adopts interface | Both (extends first) | class Kitten extends Cat implements Pet |
One rule that trips up many students: an interface never uses implements. Interfaces only extend other interfaces. Writing interface A implements B is a compile error, full stop.
Understanding this distinction is part of the broader OOP foundation that BSc CS and BTech programmes cover in depth. If you are deciding on a degree path, the overview of BSc Computer Science subjects and scope explains where Java OOP fits in the curriculum.
For working professionals thinking about where Java skills lead, the comparison of full stack developer vs software developer roles is a practical read. Both roles use the Java implements keyword extensively, but in different contexts.
If you are still building your core toolkit, the guide on software development tools to learn first pairs well with this article because knowing your IDE and build tools makes practising Java syntax far less frustrating.
The bottom line: the implements keyword in Java is the mechanism that turns abstract contracts into working, testable code. Master it and you have understood one of the most-used patterns in professional Java development. Here are three things to do this week:
- Write a small Java project with at least two interfaces and one class that implements both. Try introducing a
defaultmethod conflict deliberately and resolve it. - Read the Oracle Java Interfaces and Inheritance tutorial in full. It is free, authoritative and covers edge cases this article keeps brief by design.
- Explore 3.0 University’s online certification courses if you want to apply these fundamentals in cybersecurity or AI. Secure coding, ethical hacking and blockchain development all depend on clean OOP design, and the CEH v13 AI online course is a strong next step for anyone who wants to turn programming knowledge into a security career.
Frequently Asked Questions
What is an interface in Java?
An interface in Java is a reference type that defines a set of abstract method signatures a class must implement. It acts as a contract: any class that uses the implements keyword in Java with that interface must provide a concrete body for every abstract method declared in it. Interfaces can also contain constants and, since Java 8, default and static methods.
What does implements mean in Java?
implements is a Java keyword used in a class declaration to indicate that the class will provide concrete implementations for all abstract methods defined in one or more interfaces. It creates a binding contract enforced at compile time. If the class does not fulfil every method, the program will not compile.
What happens if a class does not implement all interface methods in Java?
If a class uses the implements keyword in Java but does not provide a method body for every abstract method in the interface, the Java compiler throws a compile-time error. The only exception is if the class itself is declared abstract, in which case it defers the obligation to any concrete subclass that extends it.
How do I implement an interface in Java?
Write class YourClass implements YourInterface in your class declaration, then define a method body for every abstract method the interface declares. Use the @Override annotation above each method to let the compiler verify the method signature is correct. If the interface has default methods, you can skip overriding those unless you want different behaviour.
Can a class implement multiple interfaces in Java?
Yes. A class can implement as many interfaces as needed by listing them after implements, separated by commas: class MyClass implements InterfaceA, InterfaceB, InterfaceC. The class must provide implementations for all abstract methods from every interface in the list. This is Java’s primary mechanism for achieving multiple-type behaviour without multiple class inheritance.
Can an interface extend another interface in Java?
Yes, and the keyword is extends, not implements. An interface uses extends to inherit the method contracts of one or more parent interfaces: interface ChildInterface extends ParentInterface. Any class that implements ChildInterface automatically inherits and must fulfil all methods from ParentInterface as well.
What is the difference between implements and extends in Java?
extends is used when a class inherits from another class, or when an interface inherits from another interface. The implements keyword in Java is used exclusively when a class adopts an interface. A class can only extend one class but can implement many interfaces. An interface can never use implements; it always uses extends when it builds on another interface.
When should I use an abstract class instead of an interface in Java?
Use an abstract class when you want to share common state (instance variables) or provide partial implementations that subclasses build on. Use an interface when you want to define a pure contract that unrelated classes can adopt independently. In modern Java (Java 8 and later), the gap has narrowed because interfaces support default methods, but abstract classes remain the right choice when shared fields or constructors are needed.
Last updated: June 2025. Reviewed by the 3University editorial team.