• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OCA / OCP Java SE 8 Programmer Practice Tests: Chapter 6 Question 12 Option B Errata?

 
Ranch Hand
Posts: 499
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sybex OCA Java 8 Study Guide (page 405 above Table 4.5)

For encapsulation, remember that data (an instance variable) is private and getters/setters are public.




OCA / OCP Java SE 8 Programmer Practice Tests: Chapter 6 Question 12 Option B Answer Errata?

Note that if stuff was declared private, Options A, B, and C would all be correct.




Practice_Test_Chapter6_Answer12_Errata_Question.png
[Thumbnail for Practice_Test_Chapter6_Answer12_Errata_Question.png]
 
Charles O'Leary
Ranch Hand
Posts: 499
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Related, OCA / OCP Java SE 8 Programmer Practice Tests: Chapter 6 Answer 24

While having getters and setters for private variables is helpful, they are not required.

 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Charles O'Leary wrote:OCA / OCP Java SE 8 Programmer Practice Tests: Chapter 6 Question 12 Option B Answer Errata?

Note that if stuff was declared private, Options A, B, and C would all be correct.


Nope! Options A, B, and C are correct if stuff was declared private. For encapsulation, there is no requirement about the access modifier for the accessor and mutator methods (if any).
 
Charles O'Leary
Ranch Hand
Posts: 499
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Roel,
Nope?  Looking at the totality of these quoted items, can they all be true at the same time?

Sybex OCA Java 8 Study Guide (page 405 above Table 4.5)

For encapsulation, remember that data (an instance variable) is private and getters/setters are public.



Should be something like?

For encapsulation, remember that data (an instance variable) is private and optional getters/setters are optionally public.

 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Charles O'Leary wrote:Nope?  Looking at the totality of these quoted items, can they all be true at the same time?


I just stated that the note in the practice tests book is spot-on. And the second part of my previous post clearly indicates that the quote from the OCA study guide is not 100% correct. It simply describes the most common form of encapsulation. Here's a similar topic about encapsulation.
 
Charles O'Leary
Ranch Hand
Posts: 499
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Roel,

not 100% correct

Sybex OCA Java 8 Study Guide Errata (as opposed to my initial topic header)?  Clearly, I'll have to leave that for the authors to decide.  

As always, very nice thorough link Roel!

(Although, "the accessor & mutator methods can" apparently also have private as you've just confirmed here. )
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The OCA version is an overly simplified definition.
 
Charles O'Leary
Ranch Hand
Posts: 499
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic