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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

OCA Java SE 8 Programmer I Study Guide - Chapter 4 - review question 8

 
Bartender
Posts: 4001
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies if this question has come up before, but I could not find anything about it. Here is:

The statement is statement E: "Immutability uses private instance variables" and the question: true or false. According to the book this statement is true.

But if you have only final immutable variables that are not private, don't we have an immutable class as well? For instance:



So I opted for 'false'. What am I missing here? It is a mixed question and includes encapsulation as well.

 
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet,
The idea is that a *good* immutable class is well encapsulated too. You are correct that your example is immutable. You won't see that on the exam though.
 
Piet Souris
Bartender
Posts: 4001
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, although I understand what you mean, my problem is that that idea is not mandatory. But if such a question is absent from the exam, then I have nothing to fear (I hope). Thanks!
 
Jeanne Boyarsky
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet,
You'll be fine. they include a very limited subset of design patterns and principles on the exam.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Piet Souris wrote:But if you have only final immutable variables that are not private, don't we have an immutable class as well?


True! But the statement mentions "variables", not "immutable variables".
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic