This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Marcus Green #3, Q44

 
Savithri Devaraj
Ranch Hand
Posts: 103
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • 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.
 
Doit
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can some one please answer ???
I think static method can be accesed through object reference also.
- Thanks.
 
Brian Podolny
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic