Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java

 
Shantanu Puranik
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Which situation we should choose Abstract and in which situation we should use Interface
 
Shraddha Jain
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if there's something u want every subclass to do exactly the same way and there are things u cannot generalize u can go for an abstract class
take IceCream for instance
it could be of many flavors - vanilla,choclate, coffee, butterscotch.........
so they all will taste() differently depending on their flavor,
but when u say melt() they simply have to ...well melt!!
so in this case u could use an Abstract class Icecream:

abstract class IceCream{
public void melt()
{
}.....melt!!!

abstract Taste taste();
}
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shantanu,

This forum is for Servlet related questions.
Moving to Java In General (Beginner).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic