• 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

mock exam q

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I saw two questions in John Hunt's mock exam which seemed ambiguous to me
Q. 34
Which methods may cause a thread to stop executing?
a) sleep();
b) stop();
C) yield();
d) wait();
e) notify();
f) notifyAll()
g) synchronized()
Select all correct answers.

Q. 30
What class must an inner class extend:
a) The top level class
b) The Object class
c) Any class or interface
d) It must extend an interface
Select the most appropriate answer
The correct answers are :
34) a,b,c,d
30) c
My question is:
1) shouldn't the question 34 have been "Which methods may cause a thread to stop running?" instead of "Which methods may cause a thread to stop executing?"
I chose (b)
2)I thought only anonymous inner classes need to implement an interface or extend a class.The way the q is phrased,it seems like all inner classes need to implement an interface or extend a class.Is this correct?
I chose (b) because all classes indirectly extend Object class
thankx in advance for your response
kris
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.
lets regard your rephrasing of the question to "running"
option1: sleep() - static method of Thread class. if a thread is put to sleep, it will go to a blocking state for the time specified. it is not necessary for the thread to own the monitor of the object at the time of invocation of sleep() (although, if the thread DOES own monitor, it will NOT release the same).
on sleeping for specified time, it will go into READY state and then the thread is at the mercy fo the scheduler.
THUS< IT HAS STOPPED EXECUTING TEMPORARILY TILL THE SCHEDULER DECIDES TO RERUN IT.
option 2: true
option 3: yield() is static method of thread class. on execution of the same, the thread will immediately from running state to waiting to run state. thus., it has stopped executing temporairly.(note that yield() is used to allow threads of same priority to run)
option 4: wait(). on execution of this method, the thread will release the monitor it holds, and will go to the waiting state. if another thread calls interrupt() on this thread, an Interrupted exception will be thrown, and the thread will go to the ready state. if the scheduler decided to run this thread , the code in the try{}catch{InterruptedException} block will be executed
thus, options 1,2,3,4,are true
hth,
chetan
 
reply
    Bookmark Topic Watch Topic
  • New Topic