This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Googling for this will most likely be the best way to go as there is tons of information out there but this is a small reason.
Abstract classes tend to be used when you have a bunch of classes that can extend the same types of thing e.g.
you could have an Employee abstract class that holds the information common to all employees and then you could have a bunch of class' such as Manager or SalesPerson that extend it, altho they will have the same common data used in the Employee class they will also have there own unique data they need to store.
Abstract methods can then also be used to force the subclass to implement some sort of behaviour.
e.g. if the abstract class defines a method -
the subclass will then have to implement this method.
Hi pretty sure that the replies above this are more technical but i think instead of you asking what is the use of abstract classes and apart from the Classic Employee - Manager example, i would suggest you to think of some real time situation in which you have an entity, which is more general but its derivatives are specific think of anything say beverage -coffee , bank account - savings account you will notice the obvious fact and that is nothing but abstract classes.
My understanding of what an abstract class is and what its used for:
As we all know everything in java (well almost everything) revolves around classes and creating objects of those classes.
Classes have their own 1.variables - to hold values and 2.Methods - to act on the variables.
When one creates an object of the class, the variables in that object gets initialized.
We do know that classes are subclassed (The exciting world of inheritance)
When a class is subclassed, the subclasses inherits those states.
Now lets consider a real life situation - lets say you create a class called Car and extend it to form various subclasses like Bmw, Ferrari...
You might define common methods of every car like(accelerate(),turn() in your Car class but
Car objects would be toooo lets say abstract and they cannot have any particular implementation of accelerate() or turn() unless its an object of a Bmw or a Ferrari.
Abstract classes are thus a solution for such situations. By defining a Class as an Abstract class you mention those behaviours that are common to cars without actually giving their definition(Y would you, a Bmw will implement it differently from a Ferrari object). Though you can also have concrete methods(meaning methods that are not abstract in an abstract class too)
◄ Sudhan ►
Joined: May 24, 2007
like we are having a abstarct class inside that we are having private methods can we call a privte method from this class