• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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
 
I think he's gonna try to grab my monkey. Do we have a monkey outfit for this tiny ad?
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic