-5

Possible Duplicate:
When shall we go for interface or abstract class in Java?

I have a doubt in java.I know about the interfaces and abstract classes.But I want to know specifically when to use interface and when to use abstract classes in java and android.I want a practical explanation with real world example not a theoretical or documented one.

Thanks.

Community
  • 1
  • 1
AndroidCrazy
  • 334
  • 8
  • 23

1 Answers1

0

The key difference is that you can implement multiple interfaces in a class, but only extend a single abstract class.

Interface is used when you only want to declare which methods and members a class MUST have. Anyone implementing the interface will have to declare and implement the methods listed by the interface.

If you also want to have a default implementation, use abstract class. Any class extending the abstract class will have to implement only its abstract methods and members, and will have some default implementation of the other methods of the abstract class, which you may override or not.

Sahil Mahajan Mj
  • 11,033
  • 8
  • 53
  • 100