I want to know that is there any use of empty abstract class in Java? If so, what is it?
Asked
Active
Viewed 5,419 times
6
-
13No use. It is the moral equivalent of a marker interface. – Stephen C Sep 28 '12 at 04:55
-
2@Stephen, What is the use of "marker interface" ? – shan Sep 28 '12 at 05:00
-
4what-is-the-purpose-of-a-marker-interface: http://stackoverflow.com/questions/1023068/what-is-the-purpose-of-a-marker-interface – Thilo Sep 28 '12 at 05:02
-
2does "empty" also preclude having parent classes and interfaces? – Thilo Sep 28 '12 at 05:03
3 Answers
7
An empty abstract class
is very much equivalent to an interface
except that it can extend a class
abstract class myAbstractClass // extends anotherClass implements anInterface
{
}
interface myInterface // extends anotherInterface
{
}
This pattern is called Marker interface and SO has a lot of good data about it already: What is the purpose of a marker interface?
-
or extend a class and "implement" one or more interfaces. Kind of like a junction type. – Thilo Sep 28 '12 at 05:01
-
-
0
you can only inherit from one abstract class. Then this is useful to avoid inheritance.

Kalla
- 165
- 2
- 12
-
4
-
1
-
-
@EJP: an abstract class can have final methods (but an "empty" one cannot). – Thilo Sep 28 '12 at 05:07
0
Yes, sometimes you need a base class for implement polymorphism.

Rodrigo
- 11
- 2
-
Yes, sure, sorry. But the main difference is that you can implement some code in your base class, or define some attributes :) – Rodrigo Sep 28 '12 at 05:06