I learnt that Object.clone() and Cloneable have some bad design decisions. However I have some more doubts:
- Why - Object.clone()has protected modifier, while others like- Object.toString(),- Object.equals()are not- protected? Why to make- clone()inaccessible to non subclasses from different packages and not to keep them public like- toString()and- equals()?
- This page says: - Object clone is a protected method, so we will have to override it to use with other classes. - I feel above fact is plain wrong as - protectedmodifier does not impose any such restriction. We can still call- clone(), but it will throw run time exception, but not compile time exception.
- How every class in Java is sub class of Objectclass? Most likely answer is "by design". But I wanted to know where this fact is enforced? Usually to extend a class, we useextendskeyword. But we dont make every custom class doextends Object. Then where does it happen? Does compiler auto generates bytecode by enforcing such restriction?
