• 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

Thread related review question from the book

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the review question (No.4) from chapter 9 of the SCJP java 6 book

***
Assume you have a class that holds two private variables: a and b ...
***

I think the author assume a and b are primitive type (such as int) and therefore in all the answer we have

return a+b;

and the answer states that answer C and D are incorrect are incorrect because only objects can be used to synchronize on, which make sense if you read only the answer. However, I went through all the possible cases. What if variable a and b are Strings? a+b will result in another string. In this case, I would say D is still incorrect because it synchronize on different variable. However, my answer for that question becomes B C and F.

Sorry if people already asked this question. I couldn't find it in the forum using the following key word

thread review question 4

Thanks
 
Cheung Chau
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, this is a dumb question. You got a and b are int from the function signature and return type
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic