×

Advanced Coding & Software Engineering Program

Duration: 1 Year (12 Months)

Join our premium 1-year program to master cutting-edge technologies and become an industry-ready Software Engineer!

Course Coverage

  • Languages: C, C++, Java, JavaScript, Python
  • Web Technologies: HTML, CSS, Bootstrap 5, MERN Stack, Full Stack Development
  • Databases: MySQL, MongoDB
  • Data Science Libraries: Pandas, NumPy
  • Development Tools: Visual Studio Code, IntelliJ IDEA, PyCharm, Postman, Git, GitHub
  • Cloud Platforms: Vercel, MongoDB Atlas

Program Highlights

  • Live Classes: Interactive sessions with real-time doubt resolution
  • Hands-On Sessions: Practical coding exercises to build real-world skills
  • Industry Experts: Learn from professionals with years of experience
  • Live Project: Work on real-world projects to apply your skills
  • Get Certificate: Earn a professional certificate upon program completion

Course Fee: Only β‚Ή1020 / month
Limited Period Offer!

Difference Between Abstract Class and Interface in Java



Last Updated on: 22nd Nov 2025 15:27:14 PM

In Java, both Abstract Classes and Interfaces are used to achieve abstraction, but they are not the same. Their purpose, usage, and design philosophy are different. Let’s learn everything in the simplest way.

 

1. What is an Abstract Class?

An abstract class is a class that can have both abstract methods (without body) and normal methods (with body).

 

πŸ‘‰ It allows 0–100% abstraction
πŸ‘‰ It can also have variables, constructors, and concrete methods

 

Example / Real-Life Meaning

A Bank has some common features (like account, customer), but rules differ in SBI, HDFC, ICICI, etc.

 

So we make an abstract Bank class and force every bank to follow some rules.

 

2. What is an Interface?

An interface is a completely abstract structure used to define only rules.

Before Java 8 → 100% abstract
After Java 8 → interfaces can have default & static methods

 

πŸ‘‰ Interfaces focus on “what to do” not “how to do”
πŸ‘‰ A class can implement multiple interfaces (supports multiple inheritance)

 

Real-Life Meaning

All online payment apps must follow RBI rules.
UPI apps like PhonePe, GPay, Paytm all implement the same UPI interface (rules).

 

Here’s the clearest and most accurate difference table between Abstract Class and Interface in Java — perfect for beginners, interviews, and quick revision.

Interface in Java — perfect for beginners, interviews, and quick revision.

 

Abstract Class vs Interface (Side-by-Side Comparison)

Feature

Abstract Class

Interface

Keyword

abstract class

interface

Inheritance

A class can extend only one abstract class

A class can implement multiple interfaces

Methods

Can have abstract + concrete methods

By default all methods are public abstract (before Java 8)
Can have default and static methods (Java 8+)

Method Body

Normal methods can have full implementation

No method body allowed (except default and static)

Variables

Can have instance variables (normal fields)

Only public static final variables (constants)

Constructors

Yes – can have constructors

No – interfaces cannot have constructors

Access Modifiers

Methods can be public, protected, private, default

Methods are always public (even if not written)

Extends / Implements

Extended using extends

Implemented using implements

Can be Instantiated?

No (but can have constructor)

No

Multiple Inheritance

Not supported (Java doesn’t allow multiple class inheritance)

Supported (a class can implement many interfaces)

Default Methods (Java 8+)

Not needed (normal methods already allowed)

Yes – using default keyword

Static Methods (Java 8+)

Yes – normal static methods

Yes – allowed in interface

Best Used For

"IS-A" relationship with shared code

"CAN-DO" or "BEHAVIOR" contract

Performance

Slightly faster (direct method call)

Slightly slower (due to dynamic dispatch in default methods)

 

Use Case

Use Abstract Class When…

  • Some common code/logic is shared

  • You want both abstract + normal methods

  • You need constructors or non-final variables

  • Partial abstraction is needed

Use Interface When…

  • You want 100% abstraction

  • You need multiple inheritance

  • You want a contract for multiple implementations

  • No common logic is required

 

Abstract Class Example — Vehicle

Every vehicle has:

  • wheels

  • engine

  • start/stop functions

But implementation depends on the vehicle type (car, bike, truck)

abstract class Vehicle {
    abstract void start();

    void fuelType() {
        System.out.println("Vehicle uses some type of fuel.");
    }
}

class Car extends Vehicle {
    void start() {
        System.out.println("Car starts with a key.");
    }
}

class Bike extends Vehicle {
    void start() {
        System.out.println("Bike starts with a self-start button.");
    }
}

 

Interface Example — Traffic Rules

All vehicles must follow the same rules:

  • Speed limit

  • Indicators

  • Helmet/seatbelt rules

interface TrafficRules {
    void speedLimit();
    void applyBrakes();
}

class CarDriver implements TrafficRules {
    public void speedLimit() {
        System.out.println("Car speed limit: 80 km/h");
    }
    public void applyBrakes() {
        System.out.println("Car applies ABS braking.");
    }
}

class BikeRider implements TrafficRules {
    public void speedLimit() {
        System.out.println("Bike speed limit: 60 km/h");
    }
    public void applyBrakes() {
        System.out.println("Bike uses disc brakes.");
    }
}

 

When to Use What?

Use Abstract Class when:

  • You want to share common code

  • Classes are related in hierarchy

  • You need constructors / non-static variables

Examples:
βœ” Vehicle → Car
βœ” Animal → Dog
βœ” Bank → SBI

 

Use Interface when:

  • You only want rules

  • You want multiple inheritance

  • Classes are not related but follow the same rules

Examples:
βœ” Online payments
βœ” Authentication systems
βœ” Sorting logic
βœ” Printable / Runnable / Clonable

 

Real-Life Example You’ll Never Forget

Scenario: You’re building a Smart Home System

You have different devices:

  • Fan

  • Light

  • AC

  • TV

 

Question: Should you use Abstract Class or Interface?

Let’s see both approaches.

abstract class SmartDevice {
    String brand;
    boolean isOn = false;

    // Constructor
    SmartDevice(String brand) {
        this.brand = brand;
    }

    // Common method (shared code)
    void turnOn() {
        isOn = true;
        System.out.println(brand + " device is now ON");
    }

    void turnOff() {
        isOn = false;
        System.out.println(brand + " device is now OFF");
    }

    // Abstract method – each device controls differently
    abstract void control();  // Fan speed, Light brightness, etc.
}

class Fan extends SmartDevice {
    Fan(String brand) {
        super(brand);
    }

    @Override
    void control() {
        System.out.println("Fan speed set to 3");
    }
}

class Light extends SmartDevice {
    Light(String brand) {
        super(brand);
    }

    @Override
    void control() {
        System.out.println("Light brightness set to 70%");
    }
}

 

Use Abstract Class when:

  • Devices are related ("is-a" relationship)

  • They share code (like turnOn(), turnOff(), brand)

  • You want constructors, fields, private methods

 

Option 2: Using Interface (When devices are different but have same ability)

interface RemoteControllable {
    void powerOn();
    void powerOff();
    void increase();
    void decrease();

    // Java 8+ default method (shared behavior)
    default void mute() {
        System.out.println("Device muted");
    }
}

class TV implements RemoteControllable {
    public void powerOn()   { System.out.println("TV ON"); }
    public void powerOff()  { System.out.println("TV OFF"); }
    public void increase()  { System.out.println("Volume Up"); }
    public void decrease()  { System.out.println("Volume Down"); }
}

class WashingMachine implements RemoteControllable {
    public void powerOn()   { System.out.println("Washing Machine Started"); }
    public void powerOff()  { System.out.println("Washing Machine Stopped"); }
    public void increase()  { System.out.println("Water Level Increased"); }
    public void decrease()  { System.out.println("Water Level Decreased"); }
}

 

Use Interface when:

  • Classes are not related (TV ≠ Washing Machine)

  • You want multiple inheritance

  • You just want a contract ("can be controlled by remote")

 

Summary – Never Forget This

Concept

Think Of

Abstract Class

A half-built house – walls are there, but rooms are incomplete

Interface

A checklist – "Must have these features"

Multiple Inheritance

Only interface allows it

Shared Code

Only abstract class

Flexibility

Interface wins

Real-World Fit

Use both wisely!

 

Use Abstract Class when you want to share code among closely related classes.
Use Interface when you want to define behavior that can be adopted by unrelated classes."

 

Keep practicing — you're doing amazing!

Happy Coding!    yes


Online - Chat Now
Let’s Connect

Inquiry Sent!

Your message has been successfully sent. We'll get back to you soon!

iKeySkills Logo