Extends vs Implements in Java

Last Updated : 13 Jun, 2026

In Java, the extends and implements keywords are used to establish relationships between classes and interfaces. The extends keyword is used for inheritance, while the implements keyword is used to provide implementations for interface methods. Understanding the difference between them is essential for designing reusable and maintainable Java applications.

  • extends is used to inherit properties and behavior from a class or interface.
  • implements is used by a class to provide implementations for interface methods.

extends Keyword

The extends keyword is used to create inheritance in Java. It allows a subclass to acquire the properties and methods of its parent class, promoting code reusability and hierarchical relationships.

  • A class can extend only one superclass.
  • An interface can extend one or more interfaces.

Syntax

class ChildClass extends ParentClass {
// Class body
}

Java
class Animal {
    void sound() {
        System.out.println("Animal makes a sound");
    }
}

class Dog extends Animal {
    public static void main(String[] args) {
        Dog d = new Dog();
        d.sound(); // Inherited method
    }
}

Output
Animal makes a sound

Note: A class can extend a class and can implement any number of interfaces simultaneously.

implements Keyword

The implements keyword is used when a class wants to implement an interface. The class must provide implementations for all abstract methods declared in the interface.

  • A class can implement multiple interfaces.
  • All interface methods must be implemented unless the class is declared abstract.

Syntax

class MyClass implements MyInterface {
// Implement interface methods
}

Java
interface Animal {
    void sound();
}

class Dog implements Animal {
    
    public void sound() {
        System.out.println("Dog barks");
    }

    public static void main(String[] args) {
        Dog d = new Dog();
        d.sound();
    }
}

Output
Dog barks

Note: An interface can extend any number of interfaces at a time.

Example: Below example demonstrating that an interface can extend multiple interface.

Java
// Defining the interface One
interface One {
    void methodOne();
}

// Defining the interface Two
interface Two {
    void methodTwo();
}

// Interface extending both the
// defined interfaces
interface Three extends One, Two {
}

Extends vs Implements

Featureextendsimplements
PurposeUsed to inherit a class or extend an interface.Used by a class to implement an interface.
UsageEstablishes inheritance.Provides implementation of interface methods.
Method ImplementationOverriding inherited methods is optional.Implementing interface methods is mandatory (unless the class is abstract).
Multiple InheritanceA class can extend only one class.A class can implement multiple interfaces.
Applicable ToClasses and interfaces.Classes only.
RelationshipCreates an is-a relationship.Defines a contract that the class must follow.
Syntax Exampleclass B extends A { }class B implements A { }
Interface SupportAn interface can extend multiple interfaces.An interface cannot implement another interface.
Comment