2

Why can't we make Cloneable as an absract class instead of making it as an interface ?

Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
SHIVA
  • 21
  • 2

2 Answers2

3

Java doesn't support multiple inheritance of classes.

If Cloneable where an abstract class you force an entire tree of objects to be Cloneable or none. You couldn't have a child being cloneable if the parent class wasn't.

In short, there is nothing to be gained by making a simple interface an abstract class unless you need to add instance field (or non public methods before Java 9)

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
2

If you did that, then anything that inherits from Cloneable couldn't inherit any other class.

Besides, there's very little point to doing that. Abstract classes are usually used when you want to share data, code, etc. between inheritors, and I'm not sure that having a default implementation of that method would be especially valuable.