What is the difference between abstract class and interface in object-oriented programming?

1 Answers
Answered by suresh

Difference between Abstract Class and Interface in OOP

Difference between Abstract Class and Interface in Object-Oriented Programming

Abstract Class:

An abstract class in object-oriented programming is a class that cannot be instantiated on its own and can contain both abstract and concrete methods. It can have constructors but cannot be instantiated directly. A subclass must implement all the abstract methods in the abstract class.

Interface:

An interface in object-oriented programming is a blueprint of a class that defines a set of methods which a class must implement. It contains only abstract methods, constant fields, and default methods. A class can implement multiple interfaces but cannot extend multiple classes.

Key Differences:

  • An abstract class can have both abstract and concrete methods, while an interface can only have abstract methods.
  • A class can only extend one abstract class but can implement multiple interfaces.
  • An abstract class can have constructors, fields, and methods while an interface cannot contain any concrete implementation.
  • Abstract classes are used to provide a common base for related classes, while interfaces are used to define a contract for implementing classes.
Answer for Question: What is the difference between abstract class and interface in object-oriented programming?