Here is something that I cannot understand.
In java.lang.Object
the clone()
is defined with protected
modifier. By definition than it can be accessed by name inside its own class definition, by name inside any class derived from it, and by name in the definition of any class in the same package.
Here the Sample
class is in another package, and obviously it can't access clone()
from the Object
class. But as Sample
derives implicitly from Object
, why is it not able to access it? The definition doesn't say that it HAS to satisfy both conditions (inside same package AND also to be a subclass).
public class Sample {
public Object foo() throws CloneNotSupportedException {
...
return someObject.clone();
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…