About Question enthuware.ocpjp.v7.2.1557 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
arnoldnitesh
Posts: 14
Joined: Thu Apr 18, 2013 2:05 pm
Contact:

About Question enthuware.ocpjp.v7.2.1557 :

Post by arnoldnitesh »

I don't understand how catch block will be execute here ? i can't see any reason that will throw InterruptedException.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1557 :

Post by admin »

Right. It is not throwing InterruptedException. The assignment is after the catch block.
-Paul.

arnoldnitesh
Posts: 14
Joined: Thu Apr 18, 2013 2:05 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1557 :

Post by arnoldnitesh »

Thank you :)

sir_Anduin@yahoo.de
Posts: 62
Joined: Fri Aug 07, 2015 2:16 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1557 :

Post by sir_Anduin@yahoo.de »

what would be the answer if the assignment where in the catch block?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1557 :

Post by admin »

If the assignment were in the catch block, you would have to interrupt the hello thread while it is sleeping. You can do that by calling t.interrupt(); in main.
However, main may still fail to print 20 because the main thread could keep running and print 0 before the code for assignment gets to run.
So you could add t.sleep(2000); after t.interrupt() to see that assignment is done and then the value is printed.

You should try out various options to see how it works.

HTH,
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests