When a method is overridden in the the sub class, the overriding methods accessibility should not be more restrictive than overridden method,i.e public method in the super class can't be overriden to private in the sub class. When this restriction is imposed in Java.
The rationale behind this all is, that if a class B extends a class A and it overrides a method m, an object of class B 'is a' A. If an object of class A publishes method m as, say, public, an object of class B has to keep this promiss: any overridden method m must be public, otherwise class B would break the contract of 'being an A'. kind regards
Joined: Jul 11, 2001
Originally posted by Jos Horsmeier: The rationale behind this all is, that if a class B extends a class A and it overrides a method m, an object of class B 'is a' A.
Beware that "is a" isn't very well defined. A more formal explanation is the Liskov Substitution Principle (LSP): objects of type B should be substitutable for objects of type A.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus