This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I meant you should use abstract classes if you need to put some common business logic there. Using interfaces you can mandate it implementers to implement *all* of the methods defined in the interface. Please have a look at this JavaRanch wiki.
Dinesh Tahiliani wrote:I am asking when to use interface and when to abstract in java.
Use Interface when you want to add optional behaviour in class. Consider Comparable interface that allows a class to make sure that its instances are ordered with respect to other mutually comparable objects. Such interface is called a Mixin. You cannot define Abstract Classes as mixin.
The constant interface pattern is a poor use of interfaces
If you have default behavior, then you must use an abstract class Otherwise, use an interface
An abstract class gives you more flexibility when it comes to evolution. You can add new behavior without breaking clients.