aspose file tools*
The moose likes Beginning Java and the fly likes Interface and abstract classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interface and abstract classes" Watch "Interface and abstract classes" New topic
Author

Interface and abstract classes

Ken Sampson
Ranch Hand

Joined: Sep 26, 2007
Posts: 45
Hello,

I am confused between an Interface and an abstract class. I would cite an example:

I consider various shape objects esp. square, rectangle etc. and consider a common behavior area which I need to determine. Should I consider an Interface or an abstract class and why?


Ken Sampson
Chiranjeevi Kanthraj
Ranch Hand

Joined: Feb 18, 2008
Posts: 288

Abstract classes

Abstract classes are used only when there is a �is-a� type of relationship between the classes.
Interfaces can be implemented by classes that are not related to one another.

You cannot extend more than one abstract class.
You can implement more than one interface.

Abstract class can implemented some methods also.
Interfaces can not implement methods.

With abstract classes, you are grabbing away each class�s individuality.
With Interfaces, you are merely extending each class�s functionality.


-Chiru
Ken Sampson
Ranch Hand

Joined: Sep 26, 2007
Posts: 45
Thanks for pointing out the differences but I am still inn confusion as to the choice between an interface or an abstract class in the above scenario. Could you please let me know what would be appropriate in the above scenario.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You can also try to read this FAQ.


[My Blog]
All roads lead to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interface and abstract classes
 
Similar Threads
interfaceand class confusion
Interface
interface and abstract methods with the same name
abstract class vs interface ?
How can I use abstract class methods