Chaturmind
LearnDSASystem DesignBlogPremium
Sign inGet started
Chaturmind

Structured learning paths for engineers who want to go deep. Written by practitioners.

Learn

  • Java
  • DSA
  • System Design
  • Spring Boot
  • AI / ML

Company

  • Blog
  • Premium
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

© 2026 Chaturmind. All rights reserved.

Built for engineers who want to go deep.


← Java Core Fundamentals

Object-Oriented Programming

  • Classes and Objects
  • Inheritance and Polymorphism
  • Interfaces and Abstract Classes

Collections Framework

  • List, Set, and Map
  • Generics

Exceptions & Best Practices

  • Exception Handling
  • equals() and hashCode()
  • String Manipulation
Chaturmind
← Java Core Fundamentals

Object-Oriented Programming

  • Classes and Objects
  • Inheritance and Polymorphism
  • Interfaces and Abstract Classes

Collections Framework

  • List, Set, and Map
  • Generics

Exceptions & Best Practices

  • Exception Handling
  • equals() and hashCode()
  • String Manipulation
HomeLearnJavaJava Core FundamentalsObject-Oriented Programming
✓ FreeIntermediate· 10 min read

Interfaces and Abstract Classes

Design flexible contracts with interfaces and share logic with abstract classes.

Published January 17, 2025


Interfaces and Abstract Classes

Both define contracts that subclasses/implementors must fulfil — but they serve different purposes.

Interface — the contract

public interface Payable {
    void pay(double amount);         // abstract (must implement)
    String getReceipt();             // abstract

    default String currency() {      // default method — optional override
        return "USD";
    }
}
  • All methods are implicitly public
  • No instance state (only static final constants)
  • A class can implement multiple interfaces
  • Java 8+: default methods allow behaviour in interfaces

Abstract Class — the partial implementation

public abstract class Shape {
    private String color;           // instance state — allowed!

    public Shape(String color) { this.color = color; }

    public abstract double area();  // subclasses must implement

    public String describe() {       // shared behaviour
        return color + " shape with area " + area();
    }
}

public class Circle extends Shape {
    private double radius;
    public Circle(String color, double radius) { super(color); this.radius = radius; }

    @Override
    public double area() { return Math.PI * radius * radius; }
}

When to use which?

InterfaceAbstract Class
StateNoYes
Multiple inheritanceYesNo (single)
ConstructorNoYes
Use whenDefining a capabilitySharing implementation

Interview Tip

"Favour interfaces over abstract classes when you only need to define a contract. Abstract classes shine when you want to share code among closely related classes."

In Java 8+, interfaces are more powerful than ever (default methods). The distinction has blurred, but abstract classes still win when you need shared mutable state.

Previous

Inheritance and Polymorphism

Next

List, Set, and Map

AI Tutor

Lesson: Interfaces and Abstract Classes

Quick actions

AI responses can be inaccurate. Verify critical information.