This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic