I would like to know:
Why overriding method cannot have a more restrictive access modifier than method being overriden?
Can anyone help me?
posted 1 week ago
So, what happens when the someMethod() is called. The reference is to a MySuperClass, so the calls is valid (someMethod is public there), but the underlying object is a MySubClass...so that call should not be allowed.
Now you might say the compiler should prevent that, since it knows that msc points to a MySubClass.