What is the Difference Between Abstract Class and Interface in Java?
Both Abstract Class and Interface are used for abstraction, but they have key differences in Java. Since Java 8, interfaces can have default and static methods.
Abstract Class
abstract class Vehicle {
String brand;
Vehicle(String brand) {
this.brand = brand;
}
abstract void start();
void stop() {
System.out.println(brand + " is stopping");
}
}
class Car extends Vehicle {
Car(String brand) {
super(brand);
}
@Override
void start() {
System.out.println(brand + " car starts");
}
}
Interface (Java 8+)
interface Drawable {
void draw();
default void print() {
System.out.println("Printing...");
}
static void info() {
System.out.println("Drawable interface");
}
}
class Circle implements Drawable {
@Override
public void draw() {
System.out.println("Drawing Circle");
}
}
Key Differences
| Feature | Abstract Class | Interface |
|---|---|---|
| Multiple Inheritance | No | Yes |
| Instance Variables | Allowed | Only constants |
| Constructors | Allowed | Not allowed |
Learn more Java OOP concepts at Online Learner!
0
likes
Your Feedback
Help us improve by sharing your thoughts
Online Learner helps developers master programming, database concepts, interview preparation, and real-world implementation through structured learning paths.
Quick Links
© 2023 - 2026 OnlineLearner.in | All Rights Reserved.
