
Difference Between Abstract Class And Interface In Java
Learn the difference between abstract classes and interfaces in Java with beginner-friendly examples. Understand use cases, key features, and when to use each in your code.

Munaf Badarpura
July 14, 2025
6 min read
If you are diving into Java, there is a chance you will get confused between abstract classes and interfaces at some point. But you are not alone, these two concepts can be confusing at first for beginners. However, they are super important for writing clean, reusable code in Java’s object-oriented world.
In this article, I am going to explain the difference between abstract classes and interfaces in a simple and easier way. I have also included code snippets to help you understand the concepts better. So, let’s jump in.
What is an Abstract Class?#
An abstract class in Java is a class that can’t be instantiated (you can’t create objects from it directly) and is meant to be extended by other classes. It’s like a half-finished blueprint—you can define some common behavior (methods) and properties (fields), but leave some parts for subclasses to fill in. Abstract classes can have both implemented methods (with actual code) and abstract methods (without code, just a signature) that subclasses must implement.
Abstract classes are great when you want to share common functionality across related classes while enforcing certain methods to be implemented by the subclasses.
Example of an Abstract Class:
Here, Animal is an abstract class with a shared method (eat) and an abstract method (makeSound) that Dog implements.
What is an Interface?#
An interface in Java is like a contract that defines a set of methods a class must implement. It’s 100% abstract by nature (though modern Java allows default methods with implementation). You can’t instantiate an interface, and it’s used to define what a class should do without caring about how it does it. Interfaces are perfect for ensuring different classes follow the same structure, even if they’re unrelated.
Since Java doesn’t allow multiple inheritance for classes, interfaces let a class implement multiple behaviors by “implementing” multiple interfaces.
Example of an Interface:
Here, Vehicle is an interface that Car implements, providing its own version of start and using the default stop method.
Key Differences Between Abstract Class and Interface#
1. Purpose#
Abstract Class:
Used when you want to share common code (like fields, constructors, or implemented methods) among related classes. It’s like a parent class that provides a partial implementation for its children.
Interface:
Used to define a standard or contract that unrelated classes can follow. It’s about ensuring specific behavior without dictating how it’s implemented (except for default methods).
2. Inheritance#
Abstract Class:
A class can only extend one abstract class because Java doesn’t support multiple inheritance for classes. This limits flexibility if you need multiple behaviors.
Interface:
A class can implement multiple interfaces, which makes interfaces great for adding multiple roles or behaviors to a class.
Example:
Here, Duck can implement both Flyable and Swimmable interfaces, but it could only extend one abstract class.
3. Fields#
Abstract Class:
Can have fields (instance variables) to store state, like name in the Animal example. These can be private, protected, or public.
Interface:
Can’t have instance fields. It can only have public static final variables (constants). This makes interfaces stateless by design.
Example:
4. Methods#
Abstract Class:
Can have both abstract methods (no implementation) and concrete methods (with implementation). This lets you share common logic.
Interface:
Historically, interfaces only had abstract methods, but since Java 8, they can have default methods (with implementation) and static methods. Still, they’re mainly about defining method signatures.
Example (Interface with Default Method):
5. Constructors#
Abstract Class:
Can have constructors to initialize fields or set up the class. Subclasses call these using super().
Interface:
Can’t have constructors since they’re not meant to be instantiated or hold state.
6. Access Modifiers#
Abstract Class:
Methods and fields can have any access modifier (public, private, protected, etc.), giving you flexibility in controlling access.
Interface:
All methods are implicitly public (unless they’re default or static), and all variables are public static final. You can’t make methods private (except private methods in Java 9+ for internal use).
7. Use Case#
Abstract Class:
Best when you have a group of related classes that share common code and state. For example, Animal as an abstract class for Dog, Cat, etc.
Interface:
Best when you want unrelated classes to follow a common behavior or contract. For example, Flyable for Bird and Airplane.
Quick Comparison Table#
Feature | Abstract Class | Interface |
---|---|---|
Inheritance | Single (extends one class) | Multiple (implements many interfaces) |
Fields | Can have instance fields | Only constants (public static final) |
Methods | Abstract + concrete methods | Abstract + default/static methods |
Constructors | Can have constructors | No constructors |
Access Modifiers | Any (public, private, etc.) | Implicitly public for methods |
Use Case | Shared code for related classes | Common behavior for unrelated classes |
When to Use Abstract Class vs Interface#
- Use Abstract Class when:
- You want to share common code (fields, methods) among related classes.
- You need to maintain state (instance variables).
- You’re modeling a clear “is-a” relationship (e.g., Dog is an Animal).
- Use Interface when:
- You need a contract for unrelated classes to follow.
- You want a class to implement multiple behaviors (e.g., Flyable and Swimmable).
- You’re focusing on “what” a class should do, not “how.”
Conclusion#
Understanding the difference between abstract classes and interfaces is crucial for writing clean, maintainable Java code. Abstract classes are perfect when you need to share common behavior and state across related classes, while interfaces are ideal for defining contracts that can be implemented by any class, regardless of its position in the class hierarchy.