• 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 Practice Tests 1Z0-808 Answers to Review Questions Chapter 6 Question 9

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

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";
       mySkier.slalom(yourSkier,mySpeed,myName);
       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: 41878
909
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.
 
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic