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

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: 41995
911
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 tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic