I was just looking over some notes and I decided to run this example:
class Testit3 extends Private {
void methodA() {
System.out.println("Inside child");
}
public static void main (
String args[]) {
Private p= new Testit3();
p.methodA();
}
}
class Private {
private double methodA() {
return 25.0d;
}
}
I got this compiler error:
Testit3.java:9: methodA() has private access in Private
p.methodA();
which I was not expecting nor due I clearly understand the wording. I understand this cast - ((Testit3)p).methodA(); - is needed to make the example work.
I was expecting a could not resolve error as the private methodA() is not picked up by the child. You get this error when you comment out or delete private methodA() in class Private. Thanks in advance.