Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > alt.comp.lang.java > #17

Re: Protected class member

X-Received by 2002:ac8:428f:: with SMTP id o15mr7751051qtl.210.1564589343728; Wed, 31 Jul 2019 09:09:03 -0700 (PDT)
X-Received by 2002:a05:6808:b22:: with SMTP id t2mr7403154oij.59.1564589343358; Wed, 31 Jul 2019 09:09:03 -0700 (PDT)
Path csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!b26no10182335qtq.0!news-out.google.com!a5ni672qtd.0!nntp.google.com!b26no10182330qtq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups alt.comp.lang.java
Date Wed, 31 Jul 2019 09:09:02 -0700 (PDT)
In-Reply-To <1S4Uy.92545$3s1.23526@fx37.am4>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=199.127.61.212; posting-account=u2uv4wkAAAAvTzPO8Dl0xfCR23oyDooM
NNTP-Posting-Host 199.127.61.212
References <1S4Uy.92545$3s1.23526@fx37.am4>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <bf5e7654-2b19-4079-bf30-5a6d53ac7b48@googlegroups.com> (permalink)
Subject Re: Protected class member
From cemaldon@gmail.com
Injection-Date Wed, 31 Jul 2019 16:09:03 +0000
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding quoted-printable
Lines 21
Xref csiph.com alt.comp.lang.java:17

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar


Thread

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