What is the difference between interface and abstract class?

By: Karthik  

  • interface contains methods that must be abstract; abstract class may contain concrete methods.
  • interface contains variables that must be static and final; abstract class may contain non-final and final variables.
  • members in an interface are public by default, abstract class may contain non-public members.
  • interface is used to "implements"; whereas abstract class is used to "extends".
  • interface can be used to achieve multiple inheritance; abstract class can be used as a single inheritance.
  • interface can "extends" another interface, abstract class can "extends" another class and "implements" multiple interfaces.
  • interface is absolutely abstract; abstract class can be invoked if a main() exists.
  • interface is more flexible than abstract class because one class can only "extends" one super class, but "implements" multiple interfaces.
  • If given a choice, use interface instead of abstract class.




Most Viewed Articles (in Interview )

How to define an Abstract class?

Interview Question: What is EJB container?

Interview Question: Where can I get help with Struts?

Interview Question: What is ActionServlet?

Interview Question: If the framework doesn't do what I want, can I request that a feature be added?

Interview Question: What about JSTL and JavaServer Faces ?

Interview Question: Is there a particularly good IDE to use with Struts ?

Interview Question: Why are some of the class and element names counter-intuitive?

Interview Question: Do ActionForms have to be true JavaBeans?

What do you understand by JSP Actions?

Explain the new Features of JDBC 2.0 Core API?

What is difference between Java Bean and Enterprise Java Bean?

What is similarities/difference between an Abstract class and Interface?

Interview Question: Why aren't the Struts tags maintained as part of the Jakarta Taglibs project ?

What is the difference between jsp:include page and @ include file?

Latest Articles (in Interview)

Comment on this tutorial