FAQ

Java

JSP

Servlet


Advertisement



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

An abstract class can be partly finished so that the child class can fill in appropriate missing info. An interface simply demands that an implementing class to implement a certain behavior, leaving it up to the implementing class as to how this is to be done. Neither interface or abstract classes can be instantiated.

What is the defferent between them?

  • An abstract class can contain both non-abstract methods (methods with a body) and abstract methods (methods without a body). An interface only contains abstract methods.
  • A class can implement multiple interfaces, but can only subclass one abstract class.
  • An abstract class can have instance variables and instance initializers. An interface cannot. Any variables defined in an interface are implicitly public, static, and final (the variables of an interface are final they must be initialized).
  • An abstract class can define constructor. An interface cannot.
  • An abstract class can have public or protected methods. An interface can have only public methods.
  • An abstract class inherits from Object and includes methods such as clone() and equals().

 


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend

Previous Next vertical dots separating previous/next from contents/index/pdf Contents

  |   |