0

Difference between private variable and protected variable?

5th Nov 2021, 3:17 AM
santhosh Kumar
santhosh Kumar - avatar
5 Réponses
+ 3
Private variables can't be accessed from outside the class. Protected variables are the same as private but with one exception that they can be accessed from derived classes
5th Nov 2021, 5:20 AM
Rishi
Rishi - avatar
+ 2
Quoi Runtime yeah you're right. They make difference when you access the class outside the package(which is mostly you'll prefer when building large projects). Default access modifier acts as private outside the package. Protected acts like protected outside the package. Inside the package, both act the same like public access modifier.
4th Jan 2022, 2:55 AM
Rishi
Rishi - avatar
4th Jan 2022, 2:52 PM
Rishi
Rishi - avatar
+ 1
Rishi So what exactly is the difference between default and protected access modifiers? They all seem to be accessible within the same package.
3rd Jan 2022, 5:52 PM
Œ ㅤ
Œ ㅤ - avatar
+ 1
Rishi I better try this out in Eclipse. Thank you!
4th Jan 2022, 7:51 AM
Œ ㅤ
Œ ㅤ - avatar