Programming Tutorials

What is the difference between interface and abstract class?

By: Karthik in Interview Tutorials on 2012-06-16  

  • 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.





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Interview )

What is the difference between interface and abstract class?

Question: Difference between forward and sendRedirect in JSP?

Explain garbage collection?

Interview Question: What is re-entrant. Is session beans reentrant. Is entity beans reentrant?

What is Collection API?

Differentiate between .ear, .jar and .war files.

Interview Question: What is the difference between EAR, JAR and WAR file?

Interview Question: Does Struts include its own unit tests?

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

Interview Question: Do ActionForms have to be true JavaBeans?

Question: How would you go about analyzing performance of an application?

Interview Question: What is the difference between Message Driven Beans and Stateless Session beans?

Interview Question: What are the call back methods in Entity bean?

What is the difference between Session Bean and Entity Bean?

Interview Question: What is Deployment descriptor?

Latest Articles (in Interview)