aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Marcus Green #3, Q44 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Marcus Green #3, Q44" Watch "Marcus Green #3, Q44" New topic
Author

Marcus Green #3, Q44

Savithri Devaraj
Ranch Hand

Joined: Jun 26, 2000
Posts: 103
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

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Aug 03, 2000
Posts: 169
I think t.yield() also should work.
static methods,variables can be called using classname.methodname or objectreference.methodname
- Thanks
Doit
Ranch Hand

Joined: Aug 03, 2000
Posts: 169
Can some one please answer ???
I think static method can be accesed through object reference also.
- Thanks.
Brian Podolny
Ranch Hand

Joined: Aug 29, 2000
Posts: 32
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
 
subject: Marcus Green #3, Q44