Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Struggling with explanation in book for OCA

Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hopefully this is the right forum for my concern.
I'm reading the book "A Programmer's Guide to Java SE 8 Oracle Certified Associate by Khalid A Mughal and Rolf W Rasmussen" but I'm struggling with
an explanation about protected member and how they can not be accessed from an superclass object in another package, only from subclasses or subsubclasses.
(Example 4.10 illustrates the point in the book)
The explanation says:

„The class SubclassB declares the field objRefA of type SuperclassA at (1). The method subclassMethodB() has the formal parameter objRefB of type SubclassB. Access is permitted to a protected member of SuperclassA in packageA by a reference of the subclass, as shown at (2) and (3), but not by a reference of its superclass, as shown at (4) and (5). Access to the field superclassVarA and the call to the method superclassMethodA() occur in SubclassB. These members are declared in SuperclassA. SubclassB is not involved in the implementation of SuperclassA, which is the type of the reference objRefA. Hence, access to protected members at (4) and (5) is not permitted as these are not members of an object that can be guaranteed to be implemented by the code accessing them.
Accessibility to protected members of the superclass would also be permitted via any reference whose type is a subclass of SubclassB. The previously mentioned restriction helps to ensure that subclasses in packages different from their superclass can access protected members of the superclass only in their part of the implementation inheritance hierarchy. In other words, a protected member of a superclass is accessible in a subclass that is in another package only if the member is inherited by an object of the subclass (or by an object of a subclass of this subclass)

My problem is the bold part. I'm no native speaker and I would be grateful if somebody could explain what the authors meant with this sentence.

Best regards
[Thumbnail for code.png]
Example Code
Posts: 23878
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The author is referring to the "responsible for implementation" rule, related to accessing protected fields.

For more information, just search for topics regarding this rule on the ranch:


Antonio Michele
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read every thread a few times and I think I have a clue now.
Will sleep over it and hopefully understand it tomorrow. ;)

Thanks a lot!

Best regards
My, my, aren't you a big fella. Here, have a tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic