Private Members
⚡ ALL INFORMATION CLICK HERE 👈🏻👈🏻👈🏻
Private Members
Sign up with email
Sign up
Sign up with Google
Sign up with GitHub
Sign up with Facebook
Asked
9 years, 7 months ago
Active
1 year, 11 months ago
10.5k 14 14 gold badges 41 41 silver badges 64 64 bronze badges
165 1 1 gold badge 2 2 silver badges 5 5 bronze badges
48.9k 32 32 gold badges 121 121 silver badges 158 158 bronze badges
To clarify, all fields and methods still exist for sub classes but they are only accessible indirectly via a non private method which can access them (or reflection)
– Peter Lawrey
Oct 9 '18 at 7:35
16.3k 2 2 gold badges 38 38 silver badges 62 62 bronze badges
16.3k 2 2 gold badges 38 38 silver badges 62 62 bronze badges
Comes down to what "inherit" means. The doc @roadRunner linked to has it both ways: near the beginning it says "A subclass inherits all the members (fields, methods, and nested classes) from its superclass." then contradicts itself saying it does not inherit private members. Personally, I think they are inherited because they are there , they're just not directly accessible . I'm curious if there's a real definition of what 'inherit' means to Java, or perhaps OO in general.
– sharakan
Apr 27 '12 at 21:57
@sharakan: today we have only a defacto definition.
– gkakas
May 31 '12 at 7:47
So if we would compare the two alternatives that seem to emerge as defacto definitions, one car see the following: assuming one that states that private members are not inherited is completely misleading and dangerous for a new developer who thinks that superclass private members (state and behavior elements) disappeared. As such only one of the definitions is safe to assume. So there is no issue of "other definition" which was the basis of my original message ("no matter of definition"). The other definition makes no assumptions ;-)
– gkakas
May 31 '12 at 8:03
JPMorgan Chase Bank, N.A. Moscow, Russia
Stack Overflow
Questions
Jobs
Developer Jobs Directory
Salary Calculator
Help
Mobile
Disable Responsiveness
Products
Teams
Talent
Advertising
Enterprise
Company
About
Press
Work Here
Legal
Privacy Policy
Terms of Service
Contact Us
Stack Exchange Network
Technology
Life / Arts
Culture / Recreation
Science
Other
Join Stack Overflow to learn, share knowledge, and build your career.
I was told that for a Java subclass it can inherit all members of its superclass. So does this mean even private members? I know it can inherit protected members.
Can someone explain this to me. I am now totally confused.
No, the private member are not inherited because the scope of a private member is only limited to the class in which it is defined. Only the public and protected member are inherited.
A subclass does not inherit the
private members of its parent class.
However, if the superclass has public
or protected methods for accessing its
private fields, these can also be used
by the subclass. A nested class has
access to all the private members of
its enclosing class—both fields and
methods. Therefore, a public or
protected nested class inherited by a
subclass has indirect access to all of
the private members of the superclass.
Members of a class that are declared
private are not inherited by
subclasses of that class. Only members
of a class that are declared protected
or public are inherited by subclasses
declared in a package other than the
one in which the class is declared.
This kind of depends on your exact usage of the word inheritance. I'll explain by example.
Suppose you have two classes: Parent and Child , where Child extends Parent . Also, Parent has a private integer named value .
Now comes the question: does Child inherit the private value ? In Java, inheritance is defined in such a way that the answer would be "No". However, in general OOP lingo, there is a slight ambiguity.
You could say that it not inherited, because nowhere can Child refer explicitly to value . I.e. any code like this.value can't be used within Child , nor can obj.value be used from some calling code (obviously).
However, in another sense, you could say that value is inherited. If you consider that every instance of Child is also an instance of Parent , then that object must contain value as defined in Parent . Even if the Child class knows nothing about it, a private member named value still exists within each and every instance of Child . So in this sense, you could say that value is inherited in Child .
So without using the word "inheritance", just remember that child classes don't know about private members defined within parent classes. But also remember that those private members still exist within instances of the child class.
You will be satisfied here 100%. I tested it on my computer and what I concluded I'm going to post it here. Just go through the program written below, see the program output and READ THE CONCLUSION given at the end.
To test it yourself, copy the whole program and save it in a file named "InheritanceTest.java" then compile it and finally run it.
Yes, a subclass can indirectly access the private members of a superclass. A subclass can't directly access the private members of a superclass.
All the public, private and protected members (i.e. all the fields and methods) of a superclass are inherited by a subclass but the subclass can directly access only the public and protected members of the superclass. If an inherited member from a superclass gives access to a private member of the superclass then the subclass can use this inherited member to access the private member of the superclass.
IMO by no way is it a matter of definition. In class-based Inheritance implies propagation of behavior to descendants. As such private members DO get inherited , and I will not go into the details how this happens.
Actually I find the "not inherited" answer to be dangerous for new developers and they do not comprehend right away that the private members are there hidden under the skin of your class and they (can) have severe impact on its behavior, size of the objects etc.
It is common that "development comes before understanding" in computer science, however lets avoid building (or destroying) our conceptualization of OOP assuming the wrong "definition" adopted by some technician writing the manual of a well known class based OO platform.
Sorry for stating something in such an old post, but the issue is always valid.
Though https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.2 shows that Private Members are not inherited. Actually, it is inherited by subclass. When we use debuggers to trace variables, it will show the private members under the label of "inherited", so just try it. there is another post discussing this question, and most of them think not inherited, which misleads many people, including me at first.
By clicking “Post Your Answer”, you agree to our terms of service , privacy policy and cookie policy
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa . rev 2021.2.2.38474
Private Members ' bills - UK Parliament
Private members in Java inheritance - Stack Overflow
PRIVATE MEMBER | meaning in the Cambridge English Dictionary
Private Members in JavaScript
Private member по Русский, перевод, Английский-Русский Словарь
Search
Search
English–Russian
Grammar
English–Polish
a member of parliament who does not have a government job
Government ministers & civil servants
aide
am
attorney general
backbencher
cabinet
Chancellor of the Exchequer
Foreign Secretary
functionary
government
Home Secretary
kitchen cabinet
marshal
Privy Councillor
procurator
public servant
regulator
secretary
Secretary of State
the Privy Council
Whitehall
See more results »
These examples are from corpora and from sources on the web. Any opinions in the examples do not represent the opinion of the Cambridge Dictionary editors or of Cambridge University Press or its licensors.
More examples
Fewer examples
private member's bill
See all meanings
Add the power of Cambridge Dictionary to your website using our free search box widgets.
Browse our dictionary apps today and ensure you are never again lost for words.
Learn
Learn
New Words
Help
In Print
Develop
Develop
Dictionary API
Double-Click Lookup
Search Widgets
License Data
About
About
Accessibility
Cambridge English
Cambridge University Press
Cookies and Privacy
Corpus
Terms of Use
This website uses cookies. For more information, please visit the Privacy and Cookies Policy .
Accept and hide this message
Getting Mature
Hotwife Talking
Lesbian Old Nl
Nudist Blonde
Porno Homemade Big Cock
![](http://mir-s3-cdn-cf.behance.net/project_modules/fs/c19f4420744793.56100f203d4d6.jpg)
![](http://mir-s3-cdn-cf.behance.net/project_modules/1400/8a6a8720744793.561010f0bdb5c.jpg)
![](http://thumbs.dreamstime.com/b/private-members-sign-outside-club-51752479.jpg)
![](http://www.luxuryretail.co.uk/wp-content/uploads/2015/04/Luxuryretail_NO-41-Mayfair-a-private-members-club-day-1024x688.jpg)
![](http://static.standard.co.uk/s3fs-public/thumbnails/image/2018/07/03/09/219334076-first-look-at-ministry-of-sounds-new-private-members-club-which-has-a-70-ft-bar.-sarah-r.jpg)
![](http://www.europeanceo.com/wp-content/uploads/2018/12/67_Pall_Mall.jpg)
![](http://images.squaremeal.co.uk/cloud/articles/restaurants/news/the-library-private-members-club-leicester-square_1000-web.jpg)
![](http://i.pinimg.com/736x/d7/ee/e6/d7eee62963c195c388fe46cfeade6fac--fitness-club-gym-fitness.jpg)
![](http://www.itsrudetostare.com/wp-content/uploads/2014/06/Dining-Room-1.jpg)
![](http://www.3interiors.com/wp-content/uploads/2017/10/RAC-01.jpg)
![](http://lifeofyablon.com/wp-content/uploads/2014/07/IMG_6369.jpg)
![](http://www.itsrudetostare.com/wp-content/uploads/2014/06/Mezzanine1.jpg)
![](http://www.thegentlemansjournal.com/wp-content/uploads/2015/12/Members-bars-the-gennaro-room-43.jpg)
![](http://notablelife.com/media/2015/05/wo4s1aw6ksclub_title.jpg)
![](http://antonialoweinteriors.com/wp-content/uploads/2017/05/TCP_0894-1.jpg)
![](http://fastly.4sqi.net/img/general/600x600/608359__g1R1AJTkjFb10o3PcNc9lyJ7CpZYXqrhb-snF7oAl8.jpg)
![](http://thegentlemensclubevents.files.wordpress.com/2018/09/le-social01.jpg)
![](http://www.luxeprivemembers.club/communities/3/004/013/564/353/images/4636073291.png)
![](http://i.pinimg.com/originals/5b/63/b2/5b63b22f42cae11183ca38dc00380663.jpg)
![](http://www.we-heart.com/upload-images/librarylondon4.jpg)
![](http://i.pinimg.com/originals/1e/20/04/1e200475b3b4528b43935e29396033bd.jpg)
![](http://www.secretentourage.com/wp-content/uploads/2018/06/fb-group.jpg)
![](http://www.seattleurbannature.org/wp-content/uploads/2017/07/the-ex-factor-guide-private-members-zone.jpg)
![](http://www.bllnr.com/images/hotels/Arts-Club.jpg)
![](http://fastly.4sqi.net/img/general/600x600/46883745_P4Lz_5oLKfvhE_na4gK2ldzWoCpUKWGlPfMfMWqs2Qc.jpg)
![](http://fastly.4sqi.net/img/general/600x600/1821902_tilncJOqDRK59AzD-XE_qyYh6g3JdBGluuADXEvmGzk.jpg)
![](http://i.pinimg.com/736x/ad/8e/f4/ad8ef46881984b119943d64184d00dce.jpg)
![](http://static.independent.co.uk/s3fs-public/thumbnails/image/2017/12/18/17/a3.jpg)
![](http://media.architecturaldigest.in/wp-content/uploads/2017/05/Indus-Club2.jpg)
![](http://images.mysecuritysign.com/img/lg/K/Private-Beach-Member-Property-Sign-K-4102.gif)
![](http://2.bp.blogspot.com/-bdurjZKTJvc/VPr8cHUMD0I/AAAAAAAAjqA/0rxm5naTpXg/s1600/WW%2BFetlife%2BParty%2BFlier%2B9.0%2B-%2Bv1.0.png)
![](http://images.mysecuritysign.com/img/lg/K/private-club-members-only-sign-k-0249.png)
![](http://3.bp.blogspot.com/-WIpgeQIQ_Ao/VDPpp2G1t8I/AAAAAAAAhNQ/1OjTuzu3ONc/s1600/WW%2BFetlife%2BParty%2BFlier%2B5.0%2B-%2Bv1.0.png)
![](http://static.auction.ru/offer_images/rd48/2019/12/23/02/big/E/ePXjtxVWH57/0137_private_members_club_2003_guest_list_select_2cd_club_music_russia.jpg)
![](http://entrepreneursclub.ltd/wp-content/uploads/2018/08/Business-Card-copy-x150-px.jpg)
![](http://wylsa.com/wp-content/uploads/2016/10/fBkW4LI3xLE-768x512.jpg)
![](http://i.ytimg.com/vi/eSLtosv0JJU/maxresdefault.jpg)
![](http://i.pinimg.com/originals/f3/df/90/f3df900421f536eaabee90f90787ab9a.jpg)
![](http://ic.pics.livejournal.com/zagran_ucheba/60364040/22905/22905_1000.jpg)
![](http://images.vice.com/vice/images/content-images/2015/03/17/south-london-porn-cinema-wanking-sam-303-body-image-1426624882.jpg)
![](http://www.thefootandankleclinic.com.au/wp-content/uploads/2017/11/medibank_members.jpg)
![](http://nashvillecity.com/wp-content/uploads/2012/06/new-member-mixer-nashville-city-club-private-membership-club-3.jpg)
![](http://www.elegantthemes.com/blog/wp-content/uploads/2018/07/004-Restrict-Access-to-WordPress-Website.jpg)
![](http://dazedimg-dazedgroup.netdna-ssl.com/1179/azure/dazed-prod/1050/6/1056102.jpg)
![](http://mzsoftware.ir/wp-content/uploads/2018/11/object-oriented-programming-in-php-2-1.png)
![](http://1.bp.blogspot.com/-5JnIAlUbqK4/V-nXZ3j6MFI/AAAAAAAAAG4/TkGFzu6QudUble5Rf-KRjZ_KoE8bhzGJgCLcB/s1600/member%2Barea.png)