I read that doing:
public final void foo() {}
is equals to:
private static void foo() {}
both meaning that the method is not overridable!
But I don’t see the equivalence if a method is private it’s automatically not
accessible…
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.
It’s true that you can not
@Overrideeither method. You can only@Overridea non-finalinstance method.final, then there’s no way you can@Overrideitstatic, then it’s not an instance method to begin withIt’s NOT true that they’re “equal”, because one is
private static, and the other ispublic final.staticcontextYou can not
@Overrideastaticmethod, but you can hide it with anotherstaticmethod. Astaticmethod, of course, does not permit dynamic dispatch (which is what is accomplished by an@Override).References
Related questions