• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Charles O'Leary
Ranch Hand
Posts: 175
4
  • Mark post as helpful
  • send pies
  • 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: 175
4
  • Mark post as helpful
  • send pies
  • 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.
 
Roel De Nijs
Sheriff
Posts: 11095
173
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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: 175
4
  • Mark post as helpful
  • send pies
  • 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: 11095
173
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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: 175
4
  • Mark post as helpful
  • send pies
  • 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. )
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36659
475
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The OCA version is an overly simplified definition.
 
Charles O'Leary
Ranch Hand
Posts: 175
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!