|
![]() |
Carey Brown wrote:Protected is like private with the exception that an immediately inherited subclass also has access.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions | How to Answer Questions | Format Your Code
I don't think so since a source file (a .java file) can have code of another class which doesn't have access to the private member of another class defined in the same source file.Stephan van Hulst wrote:An overview:
private: Only code within the same source file can access the member.
Ganesh Patekar wrote:Rather I would say private members are directly accessed only within the class they are declared in.
That JLS section, example 6.6.5 wrote:A private class member or constructor is accessible only within the body of the top level class (§7.6) that encloses the declaration of the member or constructor. It is not inherited by subclasses.
Stephan van Hulst wrote:I'm pretty sure that includes the bodies of nested classes though.
There are three kinds of actuaries: those who can count, and those who can't.
The variables are visible within a static nested class, but not accessible because of another rule that code in a static context cannot access instance members. Try it and see what sort of compiler error message you get.Liutauras Vilda wrote:. . . except static nested classes.
Agreed I was wrong. I didn't think of private members declared in inner class.Stephan van Hulst wrote:an enclosing class can access private members of a nested class.
Ganesh Patekar wrote:
Agreed I was wrong. I didn't think of private members declared in inner class.Stephan van Hulst wrote:an enclosing class can access private members of a nested class.
YesLiutauras Vilda wrote:I think nested inner class can access enclosing classes private members
No, enclosing class can access private members of inner class.not other way round.
Yes It is all about wording that's why hats off to those who document JLS.But I might misunderstanding the wording.
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
|