public class X {
class Y {
private void f () {
}
}
class Z extends Y {
{
//initializer
//f(); // error; not inherited
//this.f(); // error; not inherited
((Y)this).f(); // 1 - OK access granted
super.f(); // 2- OK access granted
}//end initializer
}
}
The above is your posted code.
Before answering to your question I do want to know do you know that in
java what is meant by not mentioning any access specifier. This is default access modifer. It meant that the members can be accessed within the same package, any subclass and non-subclass within the same package.
And also when a class is inner to another class it has access to all of the members of the outer class(here members must not be private) but the reverse is not legal.
O.K. Let me to come to your comments on 2 compiled statements.
((y)this).f() - here the code before the period will create anonymous object of type y and the statement is equivalent to creating a new object of type y and calling function f through this object. If f() is not private you can directly call it from the inner class z.
super.f() - super is the keyword to refer to the immediate outer base class in inheritance. so here it is actually calling function f of object of type y.