• Post Reply Bookmark Topic Watch Topic
  • New Topic

when to use interface & inheritence  RSS feed

 
Suhas Madap
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm liitle bit confused regarding, when to use interface & when to inheritence or abstract class?
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In either case the concrete class would inherit form its base class. That is... whether you extend or implement, you are inheriting from the class that you are extending or implementing. Making a class an interface or an abstract class is a design choice.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not exactly completely specific to SCJP. Let's move over to Java In General (Beginner).
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See whether http://faq.javaranch.com/view?InterfaceVsAbstractClass clears your doubt.
 
Dinuka Arsakularatne
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as things you can extend for one class is limited to one you have to be specific as to what you extend and see if it is a relevant one... but as for implementing, you can implement any amount as needed... basically choosing to extend an abstract class or implement an interface is purely design choice...
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Suhas Madap:
Hi,
I'm liitle bit confused regarding, when to use interface & when to inheritence or abstract class?


I pretty much quit using extends / implements keywords.
Same goes for keyword abstract.
Probably useful for advanced users who can provide the code quickly, but if your posting to this topic, the books all introduce extends / implements keywords way too early.

When you think you are ready to use them, unpack the sources and see what the author has to say about it in the comments for each class or interface you want to try out - interfaces are just portals into the underlying machine, albeit well written.

Much of these comments are pulled out verbatim by javadoc, and the resulting /docs/ are slow at first - but pay off in the long run.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!