Hi all, I would like to know the differences between abstract class and interface. When would you like to go for an abstract class ? Similarly where interface should be used? Thanx in advance Rashmi.
Abstract class and interface both are logically abstract data types. One feature of Java is, it allows to extend only one class but one can implement multiple interfaces. Thus if u have used interface, u can use it in a scenerio where class A will need to inherit behaviour from interface I as well as from some other class B by extending the other class B.
You would use an abstract class over an interface when there are some methods that you would want to provide method bodies to because they will always be implented in the same way, unless overridden. Interfaces can not have bodies to the methods, they are all abstract. Abstract classes can have as little as just one method abstract and the rest of them fully functioning methods. Bill