Free tutorials & notes in Hindi & English · Clean code examples · Mobile friendly learning
Free tutorials in Hindi & English Daily computer, mobile and IT guides Beginner friendly learning
Blog · Java · 04 Jul 2026 · Hindi + English

Java में Abstract Class vs Interface (Java 8 के बाद)

Abstract class = partial implementation + state; interface = multiple inheritance वाला contract. Java 8 default methods के साथ updated, decision table सहित.

The one-line answer

An abstract class is a partially-built class (can have state + implemented methods) that a child extends; an interface is a pure contract (what to do, not how) that a class implements — and a class can implement many interfaces but extend only one class.

Code: both in action

abstract class Vehicle {                 // abstract class
    int wheels = 4;                       // state allowed
    void start() {                        // implemented method allowed
        System.out.println("Starting...");
    }
    abstract void drive();                // abstract: child MUST implement
}

interface GPS {                           // interface
    void navigate(String to);             // implicitly public abstract
}

class Car extends Vehicle implements GPS {   // extends 1 + implements many
    void drive() { System.out.println("Car driving"); }
    public void navigate(String to) { System.out.println("Going to " + to); }
}

Car c = new Car();
c.start(); c.drive(); c.navigate("Aligarh");
Starting... Car driving Going to Aligarh

Comparison table (updated for Java 8+)

PointAbstract classInterface
Keywordextendsimplements
Multiple inheritance❌ Only one✅ Many interfaces
Instance variables✅ Any kind❌ Only public static final constants
Constructors✅ Yes (called via super)❌ Never
Method bodies✅ Normal methodsOnly default/static methods (Java 8+)
Access modifiersAny (private, protected...)Methods implicitly public

The Java 8 twist interviewers now ask

interface GPS {
    void navigate(String to);
    default void recalculate() {              // Java 8: body in interface!
        System.out.println("Recalculating route...");
    }
}
Since Java 8, interfaces can have default and static methods with bodies — so "interface has no implementation" is an outdated answer. The remaining real differences: abstract classes have state (instance variables) and constructors; interfaces do not. Say this and you stand out.

When to use which (decision rule)

  • Abstract class — related classes sharing code and fields: Vehicle → Car, Bike, Truck (all share wheels, engine logic). An "is-a with shared machinery" relationship.
  • Interface — a capability that unrelated classes can have: Comparable, Runnable, GPS. A "can-do" contract.
  • Interview line: "Abstract class for shared identity and code; interface for shared capability."

One-line answer

Abstract class एक अधूरी बनी class है (state + implemented methods रख सकती है) जिसे child extends करता है; interface एक pure contract है (क्या करना है, कैसे नहीं) जिसे class implements करती है — और class कई interfaces implement कर सकती है लेकिन extend सिर्फ एक class.

Code: दोनों action में

abstract class Vehicle {                 // abstract class
    int wheels = 4;                       // state allowed
    void start() {                        // implemented method allowed
        System.out.println("Starting...");
    }
    abstract void drive();                // abstract: child को ZAROOR बनाना है
}

interface GPS {                           // interface
    void navigate(String to);             // implicitly public abstract
}

class Car extends Vehicle implements GPS {   // extends 1 + implements कई
    void drive() { System.out.println("Car driving"); }
    public void navigate(String to) { System.out.println("Going to " + to); }
}

Car c = new Car();
c.start(); c.drive(); c.navigate("Aligarh");
Starting... Car driving Going to Aligarh

Comparison table (Java 8+ के लिए updated)

PointAbstract classInterface
Keywordextendsimplements
Multiple inheritance❌ सिर्फ एक✅ कई interfaces
Instance variables✅ किसी भी तरह के❌ सिर्फ public static final constants
Constructors✅ हां (super से call)❌ कभी नहीं
Method bodies✅ Normal methodsसिर्फ default/static methods (Java 8+)
Access modifiersकोई भी (private, protected...)Methods implicitly public

Java 8 twist जो interviewers अब पूछते हैं

interface GPS {
    void navigate(String to);
    default void recalculate() {              // Java 8: interface में body!
        System.out.println("Recalculating route...");
    }
}
Java 8 से interfaces में body वाले default और static methods हो सकते हैं — इसलिए "interface में implementation नहीं होती" पुराना answer है. बचे हुए असली अंतर: abstract classes में state (instance variables) और constructors होते हैं; interfaces में नहीं. यह बोलेंगे तो अलग दिखेंगे.

कब कौन-सा use करें (decision rule)

  • Abstract class — code और fields share करने वाली related classes: Vehicle → Car, Bike, Truck (सब wheels, engine logic share करते हैं). "is-a with shared machinery" relationship.
  • Interface — ऐसी capability जो unrelated classes में हो सकती है: Comparable, Runnable, GPS. एक "can-do" contract.
  • Interview line: "Shared identity और code के लिए abstract class; shared capability के लिए interface."

Frequently Asked Questions

Abstract class और interface में main अंतर क्या है?

Abstract class में state (instance variables), constructors और implemented methods हो सकते हैं और single inheritance support करती है, जबकि interface multiple inheritance वाला contract है जिसमें सिर्फ constants और (Java 8 से) default/static method bodies होती हैं.

क्या interface में method bodies हो सकती हैं?

Java 8 से हां — interface के default और static methods में bodies हो सकती हैं. सामान्य interface methods abstract ही रहते हैं.

Class कई interfaces implement कर सकती है लेकिन extend सिर्फ एक class क्यों?

Multiple class inheritance conflicting state के साथ diamond problem बनाती है; interfaces में instance state नहीं होती, इसलिए कई implement करना unambiguous रहता है.