class Main {
public static void main(String[] args) {
new Cloned().clone();
}
}
class Cloned implements Cloneable {
}
This gives an error, saying it is protected. None of the subclasses of object can call that method.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The problem here is that
Maindoesn’t extendCloned. As it stands,Maincan callMain.clone, but notCloned.clone.The fact that the
clonemethod is declared inObjectdoesn’t matter here. Apart from public methods, a class can only call its own inherited methods. This includes the protected ones from its super-classes, but not protected methods of others (super) classes.