Forums Register Login

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

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Also, please cite your sources. Is this a compiler error message or is it a statement made in a book?
+Pie Number of slices to send: Send
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"?
+Pie Number of slices to send: Send
They are members but subclasses can't access them directly, only indirectly through visible accessor methods.
1
+Pie Number of slices to send: Send
 

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.
1
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.


rubbery bacon. rubbery tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 290 times.
Similar Threads
dot operator
regarding protected scope
Protected access specifier.
OO in terms of Java
this and super
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:29:24.