I understand that you cannot make instances of an Abstract class,and that subclasses of Abstract classes can inheritance properties of first Abstract class, but I fail to see why Abstract classes need to exist at all when you have the normal Super classes and their sub-classes. What is the benefit/application of an Abstract class?
-
What is the benefit of object oriented programming? – Sotirios Delimanolis Nov 24 '13 at 00:01
-
What is the benefit of trying first before asking? – nanofarad Nov 24 '13 at 00:02
-
i have done. seen a few videos on you tube etc..just tells me what an abstract classes is but not the application compared to normal classes. – user3013144 Nov 24 '13 at 00:05
-
An abstract class is a template where you have the possibility of defining just part of the implementation (common functionality). – Mitch Wheat Nov 24 '13 at 00:06
-
If you have to ask, then you are not ready to hear the answer. – scottb Nov 24 '13 at 00:29
3 Answers
Abstract classes prevent an "incomplete" abstract implementation, from being instantiated.
For example, an abstract class might have abstract methods without any implementation. It wouldn't be valid to actually call such methods.
Alternatively, an abstract class may not have any actual abstract methods -- but may still be expected to add additional functionality in the subclass API, for it be useful.
The abstract
keyword is used for both of these reasons & prevents the abstract class from being instantiated.

- 13,940
- 4
- 58
- 76
abstract class Animal { }
class Dog extends Animal { }
class Cat extends Animal { }
What would the Animal
be if you could instantiate it?
You should use an abstract
class when the super class is not meant to be instantiated: it serves as a base for extending classes to rely on, but on its own it doesn't mean anything.
By having the Animal
class serve as a baseclass for Dog
and Cat
, you can define the common behaviour in there instead of having to redefine it in every subclass. Think about properties like Name
, Species
and FirstSighting
: these will be used in both Cat
and Dog
, so why not put them in a baseclass to avoid extra work and inconsistency issues?
On the other hand you don't want to just create a new Animal
either: it says nothing about the type of the animal. That's why you make it abstract
.

- 43,651
- 22
- 107
- 170
-
-
as long as the class Animal has no use, it has no right to exist at all, regardless of if its abstract or not. – b.buchhold Nov 24 '13 at 00:07
-
1Animal can contain certain properties like `name`, `species`, `first sighting`, etc. Would you redefine this in every subclass? – Jeroen Vannevel Nov 24 '13 at 00:08
-
If I instantiate Animal,I could get Dogs and Cats...SO I am now wondering why I would actually need an Abstract Animal, if I could just instantiate it from Animal (of non Abstract class)...Sorry,I think I may be missing your point here.... – user3013144 Nov 24 '13 at 00:09
-
-
1can / could. as long as you do not include such properties in the answer, it provides no value toanyone that doesn't already know about abstract classes. your answer is not wrong, just not particulary helpful. – b.buchhold Nov 24 '13 at 00:09
-
The main purpose of abstract classes/interfaces is to model an abstraction of a problem - design. The real implementation would then behave according to the abstraction.

- 142
- 2