Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

Java FAQ: Top Questions

14. What is the difference between an abstract class and an interface?

Abstract classes and interfaces both provide abstraction, but they differ in structure and use.

  • Abstract Class:
    • Declared with abstract keyword; can have abstract and non-abstract methods.
    • Can have instance fields and constructors.
    • Supports single inheritance (a class can extend only one abstract class).
    • Used for sharing code among related classes.
  • Interface:
    • Declared with interface keyword; traditionally only abstract methods (now default , static ).
    • Only constants (static final fields), no instance fields or constructors.
    • Supports multiple inheritance (a class can implement multiple interfaces).
    • Used to define a contract for unrelated classes.