• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between Abstract class and Interface

 
Saurabh Agrawal
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends ,
I am back here with some questions on interview which i have with me and i would like the clarification for the same.Please would u lemme know that wats the exact diffrence between an abstract class and an interface ??
 
Angel Dobbs-Sciortino
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One big difference is an abstract class can implement some of the methods, and an interface cannot.
Angel
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another key difference is how they are used. If you have an abstract class the assumption is that one or more concrete classes will extend it and supply any missing functionality. If you have an interface the assumption is that there will be one or more classes that will implement it. However these new classes can extend only one parent class, but can implement multiple interfaces.
Often the best design choice is to create an interface and a class (possibly abstract) that provides a default implementation of that interface. Then other designers have the choice of either using the interface or the class, whichever is most appropriate for their needs.
A good example of this is with how the AWT event listeners were implemented. For nearly every java.awt.event.XXXListener (interface) there is a corresponding java.awt.event.XXXAdapter (abstract class). It's a powerful design pattern.
[ November 17, 2003: Message edited by: Wayne L Johnson ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic