Introduction
Keywords in Java are reserved words that the compiler understands for performing specific operations or defining data structures and control flow. Among these, "extends" and "implements" are used to define inheritance relationships between classes & interfaces. Inheritance allows classes to acquire properties and methods from other classes or interfaces. Specifically, "extends" is used for class inheritance, which enables a class to inherit characteristics from another class, while "implements" is used when a class adopts the methods of an interface implementation.

In this article, we will discuss the differences between "extends" & "implements" in Java with the help of proper examples.
Extends
The "extends" keyword creates a subclass (or derived class) from an existing class, known as the superclass (or base class). The subclass inherits all the non-private fields and methods of the superclass, allowing code reuse and specialization. When a class extends another class, it forms an "is-a" relationship, meaning that the subclass is a specialized version of the superclass.
To use the "extends" keyword, you simply add it after the subclass name, followed by the superclass name.
The syntax of “extends” is:
class Subclass extends Superclass {
// Subclass fields & methods
}
By extending a class, the subclass can:
1. Inherit fields & methods from the superclass
2. Override inherited methods to provide its own implementation
3. Add new fields & methods specific to the subclass
Example
Let’s look at an example to understand how to implement this keyword in our programs. Suppose we have a base class called "Animal" with common properties & behaviors shared by all animals. We can then create a subclass called "Dog" that extends the "Animal" class to add dog-specific characteristics.
class Animal {
protected String name;
public void eat() {
System.out.println(name + " is eating.");
}
}
class Dog extends Animal {
private String breed;
public void bark() {
System.out.println(name + " is barking.");
}
}
In this example, the "Dog" class extends the "Animal" class using the "extends" keyword. The "Dog" class inherits the "name" field and the "eat()" method from the "Animal" class. It also adds a new field, "breed" and a new method, "bark()" specific to dogs.
We can create objects of the "Dog" class & access both the inherited & dog-specific members:
Dog myDog = new Dog();
myDog.name = "Buddy";
myDog.eat(); // Output: Buddy is eating.
myDog.bark(); // Output: Buddy is barking.
This example shows how the "extends" keyword allows the "Dog" class to inherit & reuse code from the "Animal" class while adding its own unique features.