Because, if allowed, the following situation is possible:
The Sub class inherits from the Parent class. The parent has a public method foo , Sub makes this method private. Now, the following code will compile fine, because the declared type bar is Parent:
Parent bar = new Sub(); bar.foo();
However, it is not clear how this should behave. One possibility is to allow it to cause a runtime error. Another would be to simply allow it, which would allow you to call the private method from the outside, just by clicking on the parent class. None of these alternatives is acceptable, so it is not allowed.
sepp2k Oct 21 '09 at 13:04 2009-10-21 13:04
source share