Christopher Collier wrote:
Juanita Dailey wrote:Hello Everyone,
Just reading through the access modifiers and almost done with Chapter one. Just curious as to why you would want to use the protected access modifier from a practical standpoint. Can anyone think of a real world example of why we would use this?
I'm sorry to say that I'm really far from having real world experience in Java.
Do you have a job with in programming and find that you don't use package access? I'm interested in this topic as well. Thanks.
I not currently working but have done a little work with Java. For the most part we used public and private access modifiers. I did some further research on this as to why we would want to use the protected access modifier. Here's a pretty good explanation, I think.
Think of your immediate family as a package. Within that package you have members and methods. There are some members/methods that I may want to protect from the outside world. For instance, I don't want my extended family(say this is another package) knowing about all of the details that go on with my children. They may be privy to some information, but things I don't want them to know I can prevent them from seeing by using the protected access modifier. For instance, I don't necessarily want my sister who is not a part of my immediate family knowing about say my kids medical condition. I can prevent this by using a protected modifier. The protected modifier says only my immediate family needs to know this information.
Hope this helps explain it a bit. If anyone else can explain it better, please feel free to jump in. The more people to jump in on this, the better we will all understand it.