6

I want to know that is there any use of empty abstract class in Java? If so, what is it?

Tim M.
  • 53,671
  • 14
  • 120
  • 163
pankaj
  • 1,643
  • 4
  • 22
  • 35

3 Answers3

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?

Community
  • 1
  • 1
Azodious
  • 13,752
  • 1
  • 36
  • 71
0

you can only inherit from one abstract class. Then this is useful to avoid inheritance.

Kalla
  • 165
  • 2
  • 12
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