What is difference between interface and abstract class?


Abstract class

  • Abstract classes can have constants, members, method stubs and defined methods.
  • Methods and members of an abstract class can be defined with any visibility.
  • A child class can only extend a single abstract (or any other) class.
  • A child class can define abstract methods with the same or less restrictive visibility.
  • Abstract  class  can  have  both  abstract and concrete methods.
  • In abstract class keyword ‘abstract’ is mandatory to declare a method as an abstract.
  • Abstract class can have  static, final  or static final  variable with any access specifier.

Interface

  • Interfaces can only have consts and methods stubs.
  • All methods of an interface must be defined as public.
  • An interface can extend or a class can implement multiple other interfaces.
  • A class implementing an interface must define the methods with the exact same visibility.
  • Interface can  have only abstract methods.
  • In an interface keyword ‘abstract’ is optional to declare a method as an abstract
  • Interface  can  have only static final (constant) variable i.e. by default.