wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Difference in Abstract classes and Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference in Abstract classes and Interfaces" Watch "Difference in Abstract classes and Interfaces" New topic
Author

Difference in Abstract classes and Interfaces

Vishnu Sharma
Ranch Hand

Joined: Feb 03, 2010
Posts: 55
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??


Regards,
Vishnu
sachin burange
Ranch Hand

Joined: Jun 24, 2008
Posts: 41
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


Regards
Sachin
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

http://faq.javaranch.com/java/InterfaceVsAbstractClass


http://muhammadkhojaye.blogspot.com/
Vishnu Sharma
Ranch Hand

Joined: Feb 03, 2010
Posts: 55
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

Joined: Jan 20, 2010
Posts: 247

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


Good luck!!
A small leak can sink a Gigantic ship.>
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38088
    
  22
Abstract classes may have implemented methods; in fact abstract classes may have all their methods implemented, or even final.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference in Abstract classes and Interfaces
 
Similar Threads
Why a class declared as Abstract, cannot have any abstract method declaration?
will it possible to definefianl abstarct class and interfaces?
Abstract Classes & Interfaces
Abstract classes and Interfaces in Project
Class and Interface