| 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: 32599
|
|
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) classData 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.
|
 |
 |
|
|
subject: why we use abstract class?
|
|
|