• 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin

OCA/OCP Practice Tests 1Z0-808 Answers to Review Questions Chapter 6 Question 9

Posts: 4
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chapter 6 answers
answer to question 9 reads:
"...Option D is also incorrect because a private instance variable is only accessible within the instance that created it...",

but further in  answer to question 11 it is stated "...Options A, C, and D are true statements....", option C being "Two instances of

the same class may access each other’s private attributes".

Again, in question 15 there is piece of code, where a private attribute of new instance is accessed in static context. I modified it slightly:

package slopes;

public class Ski {
   private int age = 18;
       void slalom(Ski racer, int[] speed, String name) {
       racer.age = 19;
       name = "Wendy";
       speed = new int[1];
       speed[0] = 11;
       racer = null;

   void setAge(int age){this.age = age;}
   int getAge() {return age;}

   public static void main(String... mountain) {
       final Ski mySkier = new Ski();
       mySkier.age = 16;
       final Ski yourSkier = new Ski();
       yourSkier.age = 17;
       final int[] mySpeed = new int[1];
       final String myName = "Rosie";
       System.out.println("yourSkier.age ="+ yourSkier.age);

and everything runs fine. By using setAge() and getAge() I checked that it is also OK if method slalom() of one instance  is used from another class, sending to parameters another instance.

So it seems that answer to question 9 should be modified, may be along with question 9 itself.
author & internet detective
Posts: 41763
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
Ooh good edge case. I've added to the errata. Thanks! I also confirmed this question wasn't used in our Java 11 book.
And then the entire population worshiped me like unto a god. Well, me and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic