• 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

Can someone explain this question to me? please

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

The above question is excerpted from mock green's SCJP exam. The resut of this question is "ABC".
I don't understand it, since the instance of class A is already created by using new A(sa),
and the array is alredy passed in, the constructor of A should initialize its own string array array. How could the value be changed?
Thank you very much in advance.
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you only have 1 sa object. Both objects A and B have their own reference to that one object but, there can be only one.
Now, the real point of this is to show how using the synchronized keyword affects the behavior in multithreaded applications. Since B has synchronized on sa, the Thread A you start can not perform operations on the sa object until B releases it (ie the synchronized block ends).
 
Andrew Symantec
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, I understand it now.
Thanks Carl
BTW, you are not from Austria, are you?
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Their are probably several points tied into what you said.

1. Passing an array reference seems different than passing a regular reference. The assignment being done is to what the reference referrs, and not to the reference. So the reference keeps its value, but what the reference points to is changed. Sort of like a pointer to a pointer if you are from a pointer coding background.
2. Though the thread is started it can not proceed until the original thread releases the lock that it needs. This often burns people when they start using SwingUtilities InvokeLater but fail to grasp that point.
3. Ugh, I can't remember the 3rd point
 
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic