Groups | Search | Server Info | Login | Register
Groups > alt.comp.lang.java > #17
| Newsgroups | alt.comp.lang.java |
|---|---|
| Date | 2019-07-31 09:09 -0700 |
| References | <1S4Uy.92545$3s1.23526@fx37.am4> |
| Message-ID | <bf5e7654-2b19-4079-bf30-5a6d53ac7b48@googlegroups.com> (permalink) |
| Subject | Re: Protected class member |
| From | cemaldon@gmail.com |
On Wednesday, April 27, 2016 at 11:25:51 AM UTC-4, JiiPee wrote: > In C++ protected members can only be called from inherited classes. In > java they can also be called from package-classes, even if not inherited. > > My questions is, that if I want only the inherited classes to see the > protected members what is the right way to do it? Is it that I have to > put them into a separate package? I have to create a new package and do > it there? Is this the normal way to do this? Jii, I think there is no easy direct answer to this. Protected access in Java is not the same as in C++, which does not have packages. In C++ protected applies to classes. The tricky thing is that in Java protected does not directly apply to class. A good practice when designing classes in either language is to favor private, and expose only member method/functions as public. If this doesn't facilitate the requirements, then in C++ open access to ancestors through protected. In Java use a package class to access default or protected attributed or method members as needed.
Back to alt.comp.lang.java | Previous | Next — Previous in thread | Next in thread | Find similar
Protected class member JiiPee <no@notvalid.com> - 2016-04-27 16:25 +0100
Re: Protected class member cemaldon@gmail.com - 2019-07-31 09:09 -0700
Re: Protected class member Graeme Geldenhuys <graemeg@example.net> - 2019-08-14 18:51 +0100
Re: Protected class member cemaldon@gmail.com - 2019-07-31 09:15 -0700
Re: Protected class member cemaldon@gmail.com - 2019-07-31 09:16 -0700
csiph-web