Abstract classes are used when you want to generalize the working of a class and let some specific
methods be implemented by the sub-classes. This way, the code is not duplicated as some general behavior
is defined in the abstract class and the sub-class only needs to implement the methods specific to its functionality.
Code duplication is avoided. Promotes good object oriented principles.
ohk but this functionality can be achieved by simple class also then why we need a special class for it.... any more good reason for it...??? thanks for your interest.
I done with my scjp...
posted 8 years ago
Abstract classes let you define some behaviors; they force your subclasses to provide others.
For example, if you have an application framework, an abstract class may provide default services such as event and message handling. Those services
allow your application to plug in to your application framework. However, there is some application-specific functionality that only your application can perform.
Such functionality might include startup and shutdown tasks, which are often application-dependent. So instead of trying to define that behavior itself, the abstract
base class can declare abstract shutdown and startup methods. The base class knows that it needs those methods, but an abstract class lets your class admit that
it doesn't know how to perform those actions; it only knows that it must initiate the actions. When it is time to start up, the abstract class can call the startup method.
When the base class calls this method, Java calls the method defined by the child class.
Well you can't have incomplete implementation with a simple class. In a simple class you have to provide all the concrete implementations. Where as in abstract
class, you can have some concrete and some incomplete implementations.
I will highly recommend you to have a look at Strategy Pattern.