class A{
private void sayA(){
System.out.println(\"Private method of A\");
}
public static void main(String args[]){
A instanceA=new B();
ins
private
means that only the class that declares the field can see it. Because you're calling instanceA.sayA();
from within class A
the method is visible and the code both compiles and runs. If you were to try to call that method from within class B
or any other class you would get the compile warning that The method sayA() from the type A is not visible