Java Notes | Interface vs Abstract class

Interface vs Abstract Class
  • Methods and members of an abstract class can have any visibility (public, protected or public), while all methods of an interface must be public.
  • A concrete child class of an abstract class must define all abstract methods. While, an abstract child class can have abstract methods.
  • A child class can extend a single class. While, an interface can extend multiple interfaces. And a class can implement multiple interfaces.
  • A child class can define abstract methods with any visibility (public, protected or public). Whereas class implementing an interface must define all interface methods as public.
  • Abstract class can have constructor but not interfaces.
  • Interface variables are public static final. Whereas abstract variables can be non-public, non-static and non-final.
  • Abstract class can have both abstract and non-abstract methods unlike interfaces where all methods are abstract.
  • Interface forces users to implement all methods when implementing it.
    Subclasses of an abstract class must implement (override) all abstract methods of its abstract super class. The non-abstract methods are inherited as they are.
  • Child class extending an abstract class with a constructor must provide a constructor with same arguments as abstract class’ constructor. Because otherwise default constructor of child class will call default constructor of abstract class with super, which will result in compilation error.

Leave a Reply