• Post Reply Bookmark Topic Watch Topic
  • New Topic

Member accessed without the dot(.) oparator must belong to same class  RSS feed

 
Daniele Barell
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the sake of dicussion, I find the sentence:
"Member accessed without the dot(.) operator must belong to same class"
is incomplete.
It should be
Member accessed without the dot(.) operator must belong to same class or its superclass"
Is it?
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it was in a superclass, it would need to have a visibility greater than private though so, technically, your suggestion would also be incomplete.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, please cite your sources. Is this a compiler error message or is it a statement made in a book?
 
Daniele Barell
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Junilu.
Junilu Lacar wrote:Also, please cite your sources. Is this a compiler error message or is it a statement made in a book?

A book:
OCA JAVA SE 8 Programmer I Exam Guide pag 73

Also private methods and variables can be considered "memebers"?
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are members but subclasses can't access them directly, only indirectly through visible accessor methods.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:If it was in a superclass, it would need to have a visibility greater than private . . .
But members of a superclass which are accessible in subclasses are inherited, so they constitute members of the subclass, so maybe the original quote was correct after all.

Private members of a superclass are not inherited by subclasses and are not accessible in subclasses. Let the Java® Language Specification (=JLS) remind you what the members of a type are. That JLS section also lets you decide whether the book is correct or not.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell is right. You have to make a distinction between members belonging to a class, which include those inherited from the superclass(es), versus the members that are declared in the compilation unit (the .java source file) of a class.
 
Daniele Barell
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:Campbell is right. You have to make a distinction between members belonging to a class, which include those inherited from the superclass(es), versus the members that are declared in the compilation unit (the .java source file) of a class.


I see.
According to JLS there's no doubt the sentence is completely right.


  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!