Hello Ranchers!
Pls look into the below code:-
class Base {
private void method(int iBase) {
System.out.println("Base.method");
}
}
class Over extends Base {
public static void main(
String args[]) {
Over o = new Over();
int iBase = 0;
o.method(iBase);
}
public void method(int iOver) {
System.out.println("Over.method");
}
}
Ans : Over.method is printed as ouput.
Per my understanding method(int iBase) is declared private in Base class, hence, it cannot be overridden. We can still overload the method. But in class Over(child of Base), Base class' private method is being overridden as it has the same return type and signature. So the compiler should complain. But actually it does not complain.
Pls clarify.
Thanks!
Neha Monga