Why can't we make Cloneable as an absract class instead of making it as an interface ?
Asked
Active
Viewed 31 times
2
-
3I'm guessing this is java? Hint: java doesn't have multiple inheritance of classes. – Raymond Chen Apr 20 '18 at 17:31
-
2Btw: [Listen to Josh Bloch and don't use `Cloneable` since it is broken](https://www.artima.com/intv/bloch13.html). – Turing85 Apr 20 '18 at 17:40
2 Answers
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.

EJoshuaS - Stand with Ukraine
- 11,977
- 56
- 49
- 78