+ 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.

31st Oct 2019, 12:22 PM
Avinesh
Avinesh - avatar
5 Answers
+ 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.
2nd Nov 2019, 7:57 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
2nd Nov 2019, 7:59 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Yes but only through inheritance. If I am correct you have to use super to call the protected method. super.myMethod();
3rd Nov 2019, 3:56 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Appreciate it, thanks man.
3rd Nov 2019, 1:41 AM
Avinesh
Avinesh - avatar
+ 1
Will try that, thanks.
3rd Nov 2019, 4:05 PM
Avinesh
Avinesh - avatar