class One {
void foo() { }
}
class Two extends One {
private void foo() { /* more code here */ }
}
Why is the above snippet of code wrong?<
It would break polymorphism.
If you have a Two instance stored in a Two variable, then it would make sense that foo cannot be called. But if you store a Two instance in a One variable, you only know about One. But One's have a public foo, and that can be called. This would be an inconsistency and would be really weird.