I am trying to clone a object of class Integer, which does implement the cloneable inteface.
Integer a = new Integer(4);
Integer b = a.clone();
Sure, all methods in
Object are inherited. The
clone method however is
protected, thus only accessible from within subclasses.
The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.
The reason why you can call
clone() in most other circumstances is that the subclass "opens it up" by overriding it with the
public access modifier.