Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-09-2008, 10:55 AM
Member
 
Join Date: Apr 2008
Posts: 91
javarishi is on a distinguished road
Interface Vs Abstract Class
Can AnyOne Say, When Exactly, We Need To Go For An Abstract Class, And An

Interface? On Basis Of What We Need To Make A Decision?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-09-2008, 11:16 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,875
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
In my programming practice, if I want to change something on my design frequently, I go for an interface.

Abstract class used for some common behaviors.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 11:55 AM
Member
 
Join Date: Apr 2008
Posts: 91
javarishi is on a distinguished road
Thanks Eranga. Abstract Class Is Clear. In Case Of Interface, you mean to say if the method signature changes frequently, then we need to put it inside an interface? Can you please, brief me please?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-09-2008, 12:15 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,875
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Yep, you are right. Say I have an interface like this,

Code:
interface Test{ boolean isLess(Object a); boolean isSmall(Object a); boolean isEqual(Object a); }
In all case I'm looking different implementation, with the same arguments actually. There are large number of such cases can be found in Java.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-14-2008, 03:43 AM
Member
 
Join Date: Jun 2008
Posts: 22
ferranb is on a distinguished road
Use abstract classes when you want to "force" to derived classes to implement some code.

Use interfaces when you want to define a behavior that can define any class that implement it on different hierarchies. When a class implements an interface is saying "I'm able to do that especific thing". When you subclass a class you are saying "I'm like my parent and more".

Ferran

Ferran
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-15-2008, 06:43 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 518
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Abstract classes vs Interfaces
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is the Priority for execution of Interface class and a Abstract class Santoshbk Advanced Java 0 04-02-2008 08:04 AM
Abstract Class gapper New To Java 4 01-31-2008 02:25 PM
Abstract Class question maa11235 New To Java 1 01-05-2008 11:30 PM
Can this be done using abstract class?? romina New To Java 2 07-26-2007 10:09 AM
difference between Abstract and interface mrark New To Java 1 06-27-2007 06:21 PM


All times are GMT +3. The time now is 06:40 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org