So, we have
public abstract class A{
protected abstract String f();
}
public class B extends A{
protected String f(){...}
}
public class C extends A{
protected String f(){
A b = (A) Class.forName("B", true, getClass().getClassLoader()).newInstance();
return b.f();
}
This doesn't allow me to access b.f()
, saying that B.f()
is in the protected scope, however f
was protected by A
, and since C
extends A
, it should also get access to f()
.
The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.
If you want to access the B.f(), you should have the C class defined in the same package as B.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With