overriding private methods
807597Nov 1 2005 — edited Nov 1 2005Is it possible to override private methods??
class A {
private void print() {
System.out.println("Hello Super");
}
}
class B extends A{
public void print() {
System.out.println("Hello Sub");
}
}
class C {
public static void main(String args[]) {
A a=new B();
a.print();
}
}
According to overriding rules the sub class method should not be more restrictive than the super class method. SO we are making it public (From private).
So the above code is an example of overriding but when compiled it gives error.
Please explain why??