• 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

Marcus Green #3, Q44

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given a reference t to a class which extends thread, which of the following will cause it to give up cycles to allow another thread to execute
1.t.yield()
2.yield()
3.yield(100)
4.yield(t)
The answer given is 2. I think 1 and 2 are both right. I just tried it out.
Savithri
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Savithri Devaraj:
Given a reference t to a class which extends thread, which of the following will cause it to give up cycles to allow another thread to execute
1.t.yield()
2.yield()
3.yield(100)
4.yield(t)
The answer given is 2. I think 1 and 2 are both right. I just tried it out.
Savithri


As yield() is static method in Threda class, it can only be invoked as yield() NOT as t.yield().Correct me if I am wrong.
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think t.yield() also should work.
static methods,variables can be called using classname.methodname or objectreference.methodname
- Thanks
 
Doit
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can some one please answer ???
I think static method can be accesed through object reference also.
- Thanks.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Doit:
Can some one please answer ???
I think static method can be accesed through object reference also.
- Thanks.



Static methods can be called by using the class name or by using an object reference( As in Thread.yield()or t.yield() where t is a reference to a thread. Within a class that extends Thread
yield() can be called with it's signature only ). For clarity it is usually better to use the class name as this makes it clear that the method is static. Both 1 and 2 in the question are correct.
 
reply
    Bookmark Topic Watch Topic
  • New Topic