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.



Archived Comments


Most Viewed Articles (in Interview )

Interview Question: What is abstract schema?

Interview Question: Why does EJB needs two interfaces(Home and Remote Interface)?

What are the call back methods in Session bean?

Interview Question: What is the difference between sessioncontext and entitycontext?

Interview Question: What is Local client view in EJB?

Interview Question: What is lazy loading?

Interview Question: What is deployment descriptor?

Explain the Polymorphism principle.

Interview Question: How do I install Struts?

What is the difference between Session Bean and Entity Bean?

What types of comments are available in the JSP?

Interview Question: How is the MVC design pattern used in Struts framework?

Question: Explain the life-cycle methods in JSP?

Question: What is a Hidden Comment in JSP?

What is difference between Java Bean and Enterprise Java Bean?

Latest Articles (in Interview)

Comment on this tutorial