Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference in Abstract classes and Interfaces

 
Vishnu Sharma
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the exact difference between abstarct class and interface. Both of these only provide the declaration with no body of method. Other than this, all interfaces can have only abstract methods, so is that mean all interfaces are abstarct classes??
 
sachin burange
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Abstract class can contain default implementation of the method where as interface cant.
2. Abstract class can contain abstract and non-abstract methods where as interface all methods should be abstract.
3. If implemented class is already extending some another abstract class then no other abstract class can be extended where as
this is not true in case of interface.


Regards
sachin
 
Vishnu Sharma
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sachin burange wrote:1. Abstract class can contain default implementation of the method where as interface cant.
2. Abstract class can contain abstract and non-abstract methods where as interface all methods should be abstract.
3. If implemented class is already extending some another abstract class then no other abstract class can be extended where as
this is not true in case of interface.


Regards
sachin


What exactly means default implementation of method?? As per my understanding, abstract methods do not have implementations.
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interfaces are used to produce multiple inheritence.A class may implements one or more interfaces thereby serves indirectly to multiple inheritence. but a class can extend only one abstract class.
abstract class may have non abstract methods but interface cant.

raza
 
Campbell Ritchie
Sheriff
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abstract classes may have implemented methods; in fact abstract classes may have all their methods implemented, or even final.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic