• 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

Brainbench Exam Question

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the advantage of declaring a synchronized method as final? How does it help synchronization?
I do not remember the multiple choice answers given nor do I remember which one I chose.
So far as I could see there was no distinct advantage. It is just a synchronized method which cannot be overridden.
Can anyone shed some light.
SJ
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The example always used for sychronized methods is an ATM withdraw method in which there are more than one ATM cards for one account. Therefor, the withdraw() method would be sychronized to insure that the account could only be accessed once at a time. If the method was also final, it would add an additional layer of protection.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sajan,
Jenna is right. You would want to make a synchronized method final for security purposes. You make a method synchronized for safety... so more than one thread won't access things at the same time and mess things up. You make a method final for security... so someone can't make a class that is a subclass of your method that can override important things (like in the ATM example... make a subclass of the synchronized method that does everything the original does... plus puts 0.5 cents into my account out of every transaction! )
HTH,
-Nate

P.S. - I actually have heard rumors of the 0.5 cent scam working in the distant past of computing ( you know... in the 60's-70's )... but it may just be an urban legand...
reply
    Bookmark Topic Watch Topic
  • New Topic