+ 4
Protected access modifier
Superclass in Package1 can be subclassed in Package2 and yet the protected member of superclass can be accessed. I want to know how? Can anyone help me with a code which may be invokes a protected method from the superclass.
5 Respostas
+ 2
I would say this is how "protected" works.
If a super class has a protected method than a subclass has access (from same package and from different package).
You need to try it out with your own IDE. Sololearn does not support packages.
+ 2
The first answer contains an infographic about the different access modifier:
https://stackoverflow.com/questions/215497/what-is-the-difference-between-public-protected-package-private-and-private-in
+ 2
Yes but only through inheritance. If I am correct you have to use super to call the protected method.
super.myMethod();
+ 1
Appreciate it, thanks man.
+ 1
Will try that, thanks.