aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Mock exam question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Mock exam question" Watch "Mock exam question" New topic
Author

Mock exam question

santhoshkumar samala
Ranch Hand

Joined: Nov 12, 2003
Posts: 156


Answer given is 1, when I compile and run Iam getting runtime exception.. but I have two queries about this question

1)In k&b book it is mentioned that wait,notify and notify all must be called from synchronized block, so why I am not getting compile error here?

2)can we call start() method like above?
[ December 19, 2005: Message edited by: santoshkumar samala ]

santhosh<br />SCJP,SCWCD
Leonardo Rafaeli
Ranch Hand

Joined: Dec 12, 2005
Posts: 58
runtime exception because the wait() is not on a synchronized block


SCJP 1.4, SCWCD 1.4, SCBCD 5, OCUP, SCEA 5 (I), Oracle SOA Implementation Specialist, IBM Websphere Lombardi 7.1 Fundamentals
Blog: [url]http://www.leozin.com.br/blog[/url]
Naresh Gunda
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
In k&b book it is mentioned that wait,notify and notify all must be called from synchronized block,

Yes. Otherwise Runtime Exception. No compilation error.

java.lang.IllegalMonitorStateException: current thread not owner
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
This question (originally) comes from one of my mock exams, and it includes the following explanation with the answer.

Compilation but runtime error.

At runtime an error indicating java.lang.IllegalMonitorStateException because the wait call is not within synchronized code. Changing the signature of payBill to public synchronized void payBilll would remove the runtime error, causing the program to run and then pause with no output.

Does the explanation look correct, and if so is there something I can do to change the answer to make the explanation more clear?
[ December 19, 2005: Message edited by: Marcus Green ]

SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
santhoshkumar samala
Ranch Hand

Joined: Nov 12, 2003
Posts: 156

Thanks Marcus,

I have not seen any explanation there, may be because I am accessing as guest
 
Consider Paul's rocket mass heater.
 
subject: Mock exam question