In Java, the extends keyword makes a class inherit the fields and methods of one superclass (or makes an interface inherit other interfaces), whereas the implements keyword makes a class promise to provide the methods of one or more interfaces. That is the core of extends vs implements in Java.
We use extends to reuse and specialize existing code, and implements to make a class fit a contract that other code depends on. Both words are reserved keywords, so they cannot be used as identifiers.
The following example declares a parcel class for a delivery app that uses both keywords in one declaration.
class ExpressShipment extends Shipment implements Trackable, Insurable {
ExpressShipment(String id, double weightKg) { super(id, weightKg); } // calls the Shipment constructor
@Override double cost() { return super.cost() + 10; } // reuses inherited code
public String trackingId() { return "EX-" + id; } // required by Trackable
public double insuredValue() { return 500; } // required by Insurable
}
Notice that extends names a single class and comes first, while implements lists two interfaces. We look at each keyword on its own, combine them, compare them in a table, and cover default-method conflicts, the extends keyword inside generics, and a real-world design.
1. Java extends
In Java, we inherit the fields and methods of a class by extending it with the extends keyword. A class is allowed to extend one and only one class, because Java does not support multiple inheritance of classes, which avoids the diamond problem with inherited state and constructors. A class without an extends clause extends java.lang.Object.

1.1. Extending a Class
The subclass gets every inherited member and can override instance methods to change their behavior. The following example is the base class of the delivery app, and ExpressShipment from the intro extends it.
class Shipment {
protected final String id;
protected final double weightKg;
Shipment(String id, double weightKg) {
this.id = id;
this.weightKg = weightKg;
}
double cost() {
return 5 + weightKg * 2;
}
}
Shipment standard = new Shipment("P1", 2.0);
double standardCost = standard.cost(); // 9.0
Shipment express = new ExpressShipment("P2", 2.0);
double expressCost = express.cost(); // 19.0, the override runs
The subclass calls the superclass constructor with super(…), and super.cost() reuses the inherited formula before adding the express fee. Constructors are not inherited, so ExpressShipment declares its own. A class marked final, such as String, cannot be extended at all.
The JDK uses the same mechanism. The ArrayList class extends AbstractList, which in turn extends AbstractCollection, so ArrayList has the methods and behavior of both parent classes.
1.2. Extending Interfaces
An interface can extend another interface with the same extends keyword, and unlike a class it can extend several interfaces at once. An interface never uses implements, because it does not implement anything itself.
interface Trackable {
String trackingId();
default String trackingUrl() {
return "https://track.example.com/" + trackingId();
}
}
interface Insurable {
double insuredValue();
}
interface PriorityParcel extends Trackable, Insurable {
int priority();
}
A class that implements PriorityParcel must provide all three abstract methods, trackingId(), insuredValue() and priority(), and it receives trackingUrl() as a default method.
2. Java implements
In Java, interfaces enforce a contract onto classes. A class uses the implements keyword to sign that contract, and the compiler checks that the class provides a body for every abstract method of every listed interface. If the class leaves any of them out, it must be declared abstract.
class Locker implements Trackable {
private final int number;
Locker(int number) {
this.number = number;
}
@Override
public String trackingId() {
return "LK-" + number;
}
}
Trackable locker = new Locker(7);
String lockerId = locker.trackingId(); // "LK-7"
String url = locker.trackingUrl(); // "https://track.example.com/LK-7"
The implementing method must be public, because interface methods are implicitly public and an override cannot reduce visibility. Since Java 8, default methods such as trackingUrl() come with a body, so the class does not have to override them.
We can implement any number of interfaces. For example, the ArrayList class implements four interfaces, List, RandomAccess, Cloneable and Serializable, next to the class it extends. Enums and records can implement interfaces too, but they cannot extend a class, because an enum already extends java.lang.Enum and a record extends java.lang.Record.
record DroneDelivery(String code) implements Trackable {
public String trackingId() { return "DR-" + code; }
}
Trackable drone = new DroneDelivery("9");
String droneUrl = drone.trackingUrl(); // "https://track.example.com/DR-9"
3. Using extends and implements Together
A class can extend one class and implement several interfaces in the same declaration, as ExpressShipment does in the intro. The extends clause always comes before the implements clause, and the compiler rejects the reverse order.
// does not compile: implements must follow extends
class BulkShipment implements Trackable extends Shipment { }
The resulting object belongs to all of its types at once, so we can pass it wherever any of them is expected. The instanceof checks confirm it.
ExpressShipment parcel = new ExpressShipment("P3", 1.0);
boolean isShipment = parcel instanceof Shipment; // true
boolean isTrackable = parcel instanceof Trackable; // true
boolean isInsurable = parcel instanceof Insurable; // true
String parcelId = parcel.trackingId(); // "EX-P3"
double insured = parcel.insuredValue(); // 500.0
4. Differences between extends and implements
Use extends when the new type is a more specific version of an existing type and should reuse its code, and use implements when a class must offer a capability that other code calls through an interface. The rules differ for classes and interfaces, mainly in how many types each keyword accepts.
| Point | extends | implements |
|---|---|---|
| Used by | Classes (to extend a class) and interfaces (to extend interfaces) | Classes, enums and records (to implement interfaces) |
| How many | A class extends one class; an interface extends any number of interfaces | Any number of interfaces |
| What we get | Fields, methods and the parent type | Only the type and default methods; no instance fields |
| Obligation | Override abstract methods if the parent is abstract; other methods are optional | Implement every abstract method, or declare the class abstract |
| Constructors | The subclass constructor calls a superclass constructor | Interfaces have no constructors |
| Blocked by | A final class or a sealed class that does not permit us | A sealed interface that does not permit us |
| Position in the declaration | First | After extends |
Since Java 17, sealed classes and interfaces restrict both keywords to the subtypes listed in their permits clause. A class outside that list gets a compile error whether it uses extends or implements.
5. Two Interfaces With the Same Default Method
Implementing several interfaces is safe for abstract methods, because one body satisfies all of them. A conflict appears only when two interfaces provide a default method with the same signature. In that case, the class must override the method, and it can pick one of the inherited bodies with the Interface.super.method() syntax.
interface Fragile {
default String label() { return "handle with care"; }
}
interface Refrigerated {
default String label() { return "keep below 5 C"; }
}
class VaccineBox implements Fragile, Refrigerated {
@Override
public String label() {
return Fragile.super.label() + ", " + Refrigerated.super.label();
}
}
String label = new VaccineBox().label(); // "handle with care, keep below 5 C"
Without the override, the compiler reports that VaccineBox inherits unrelated defaults for label(). Superclass methods win over interface defaults, so a label() inherited through extends would resolve the conflict too.
6. The extends Keyword in Generics
Inside angle brackets, extends has a broader meaning. A bounded type parameter such as <T extends Shipment> accepts Shipment or any subtype, and the bound can be an interface as well, because generics never use implements. With &, we can require a class and interfaces at the same time.
static <T extends Shipment & Trackable> String summary(T parcel) {
return parcel.trackingId() + " costs " + parcel.cost();
}
String summary = summary(new ExpressShipment("P4", 2.0)); // "EX-P4 costs 19.0"
The method accepts only objects that extend Shipment and implement Trackable, so a plain Shipment or a Locker is rejected at compile time. When a bound mixes a class and interfaces, the class comes first. The generics tutorial covers bounds and wildcards such as ? extends T in more detail.
7. Choosing Between Them in a Real Application
Say a delivery app works with three courier companies. Every courier needs a different API call to book a pickup, but all of them share the same retry and logging code. A clean design defines a CourierClient interface for the booking contract, which the order service depends on, and an abstract BaseCourierClient that implements the interface and holds the shared retry code.
interface CourierClient {
String bookPickup(String parcelId);
}
abstract class BaseCourierClient implements CourierClient {
private int attempts;
@Override
public String bookPickup(String parcelId) {
attempts++;
return callApi(parcelId);
}
int attempts() { return attempts; }
protected abstract String callApi(String parcelId);
}
class FastCourierClient extends BaseCourierClient {
@Override
protected String callApi(String parcelId) {
return "FAST-" + parcelId;
}
}
CourierClient client = new FastCourierClient();
String booking = client.bookPickup("P5"); // "FAST-P5"
Each courier class uses extends to reuse the retry code, while the rest of the app sees only the interface. In tests, we can implement CourierClient with a small fake without touching the class hierarchy. The JDK follows the same pattern with List and AbstractList, and the interface vs abstract class guide explains when each one fits. The same reasoning is behind preferring implements Runnable over extends Thread, as described in Runnable vs Thread.
Both keywords build on inheritance, one of the four OOP concepts. A deep extends chain couples classes tightly, so many teams keep class hierarchies shallow and prefer interfaces plus composition.
8. extends vs implements FAQs
Most follow-up searches ask what each keyword is allowed to combine with.
8.1. Can a class extend and implement at the same time?
Yes. A class can extend one class and implement any number of interfaces, written as class A extends B implements C, D. The extends clause must come first.
8.2. Can an interface implement another interface?
No. An interface uses extends to inherit other interfaces, for example interface PriorityParcel extends Trackable, Insurable. The word implements is a compile error in an interface declaration.
8.3. Can a class extend multiple classes in Java?
No. A class has only one direct superclass. If we need behavior from several sources, we implement several interfaces, use default methods, or delegate to other objects through composition.
8.4. Can a class extend an interface?
No. A class uses implements for interfaces; class A extends Trackable fails with the message no interface expected here. Only interfaces and generic bounds use extends with an interface type.
8.5. Does a class have to implement every interface method?
Only the abstract ones. Default and static methods already have bodies, and an abstract class can leave abstract methods for its subclasses to implement.
9. Conclusion
The extends keyword creates an inheritance link to one superclass, or to several superinterfaces when the declaring type is an interface. The implements keyword makes a class, enum or record fulfill the contracts of any number of interfaces.
When both appear, extends comes first. Default-method clashes are solved with an override and Interface.super, and inside generics extends covers both classes and interfaces. In application code, an interface for the contract plus a small abstract base class for shared code gives us the benefits of both keywords.
10. References
- JLS 25, Superclasses and Subclasses
- JLS 25, Superinterfaces
- JLS 25, Superinterfaces of an Interface
- Oracle Java Tutorial, Inheritance
- ArrayList Javadoc
Happy Learning !!