• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Doubt on mock exam

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this question in planet java mock exam .
I belive ans is C and B ,because when wait() is excuted it will result in exception raised.
but as per the java planet ans is B.

What is the effect of issuing a wait() method on an object

A)If a notify() method has already been sent to that object then it has no effect
B)The object issuing the call to wait() will halt until another object sends a notify() or notifyAll() method
C)An exception will be raised
D)The object issuing the call to wait() will be automatically synchronized with any other objects using the receiving object.
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you think an exception will be raised if wait() method is called?
Call to wait() method should be in try/catch block to handle InterruptedException if some other thread or some thing else interuppts this thread which is in waiting state.

Murali...
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy ranchers!

Java Planet is correct.

An exception (i.e. an illegal monitor state exception) will be raised only if the current thread is not synchronized on that object.

But the question didn't say anything about synchronization. It CAN throw an exception, but the call on wait doesn not throw exceptions generally. Therefore answer C is not correct.

Yours,
Bu.
 
sundar sankar
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for the detailed explain.
regerds
sankar
 
I am displeased. You are no longer allowed to read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic