• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Difference in Abstract classes and Interfaces  RSS feed

 
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??
 
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.
 
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
 
Marshal
Posts: 59745
188
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!