When it comes to over - riding , there is only one rule related to access specifiers
"The subclass overridden method cannot have weaker access than super class method"
why is the child class restricted to have stronger access specifier ? what draw back may it invite , I am guessing something to occur on design level.
let us consider the rule didn't exist , in that case 1 : parent class having weaker access say public 2 : child class having stronger access say private
so if any external class tries to access the method , it still can access from child class as it will be inherited in child class and will be available to use with object reference
please clarify.
public class A
{
public void methOne(int a)
{
// something
}
}
class B extends A
{
private void methOne(int a)
{
// something else
}
}
class C
{
public static void main(String args[])
{
new B().methOne();
// in this special case after removing the specifier rule it will execute the method from parent class.
}
}