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...
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...
It's true that you can not @Override
either method. You can only @Override
a non-final
instance method.
final
, then there's no way you can @Override
itstatic
, 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 is public final
.
static
contextYou can not @Override
a static
method, but you can hide it with another static
method. A static
method, of course, does not permit dynamic dispatch (which is what is accomplished by an @Override
).
Neither can be overridden, but for very different reasons. The first is a public nonstatic method, while the secod is static. So the first is not overridable only because it has been declared final, while the second, being static, can never be overridden.
Note that from the first you can access nonstatic members of the class, while from second you can't. So they are used in very different ways, thus are not "equal".