Skip to content
C

Java Interview Questions

Abstract Classes Interview Questions

Abstract class mechanics, constructors and fields, and a deep comparison with interfaces.

Question 1: What is a deep, practical comparison between an abstract class and an interface?

Ans

An abstract class can hold instance state and constructors and is extended by only one subclass at a time, single inheritance, while an interface traditionally holds no instance state, has no constructor, and can be implemented by any number of classes at once, multiple implementation. An abstract class is chosen when subclasses share real implementation and a genuine "is-a" relationship; an interface is chosen when unrelated classes need to guarantee the same capability.

Example

java
abstract class Vehicle { // shared state + implementation, single inheritance int speed; void printSpeed() { System.out.println(speed); } } interface Drivable { void drive(); } // pure capability, multiple implementation class Car extends Vehicle implements Drivable { public void drive() { speed += 10; } }

Important Point

A class can extend only one abstract class but implement many interfaces — this single fact drives most real design decisions between the two.

Continue Your Preparation