File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes why we use abstract class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why we use abstract class?" Watch "why we use abstract class?" New topic
Author

why we use abstract class?

manas ranjan mandal
Ranch Hand

Joined: Apr 02, 2008
Posts: 97
i want to know that what is the need of using abstract class in java programm?we can use interface every where without extends abstract class?
Manuel Leiria
Ranch Hand

Joined: Jul 13, 2007
Posts: 171
DO you understand the concept of abstract class?


Manuel Leiria<br /> <br />--------------<br />Peace cannot be kept by force; it can only be achieved by understanding. <br /> Albert Einstein
ch hemasundar
Greenhorn

Joined: Jul 01, 2008
Posts: 6
Hi Manas,
Abstarct classes are meant for 'abstracting'.
means if some classes are having common behaviour, instead of writing evry time the same thing in each class, write that in one class and ask the other classes to use it[by making the classes as subclasses to the abstract class].
this is nothing but inheritance.
To summarise:
Use abstract classes when you want default behaviour for some classes
Use interfaces when you want different behaviour different classes.

hope this helps you

regards
hemasundar
manas ranjan mandal
Ranch Hand

Joined: Apr 02, 2008
Posts: 97
thanks for clearing my doubt
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38837
    
  23
I have a rough rule-of-thumb:
  • Functionality: likely to be different in all parts: Interface.
  • Data, and functionality, parts will be mostly the same, parts different: abstract class.
  • Data, and functionality: actually working, if extended only with slight changes: ordinary (concrete) class
  • Data and functionality, no changes planned: ordinary (concrete) class with final modifier.
  • Data, and maybe functionality: read-only: enum members.
  • Remember this is very rough and ready and not at all strictly defined, but there is a spectrum from interfaces where everything is intended to be changed to enums where everything is fixed a bit like a read-only file.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: why we use abstract class?