Originally posted by pradeep bhat:
Can a method with no access modifier be overriden by a method marked protected?
Java ranch says it is True.
But I say it is "false".
A method can over ride another method if its access modifier is same or less restrictive than the overriden method.
Some one plz clarify.
The method with no modifier is more restrictive than the method marked protected..
e.g.
// supper class
package sample;
public class testObj
{
protected void tstMethod(int i){
}
}
//sub class
package sample;
class tstObj2 extends sample.testObj
{
void tstMethod (int i) {
}
}
error in subclass : access modifier more restrictive.
HTH