• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

q from jiris.com

 
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is wrong with the following code, if any?
(Select one correct answer)
--------------------------------------------------------------------------------

public class Test005
{
public static void main(String args[])
{
Thread.yield(); //1
Thread t = Thread.currentThread();
synchronized(t) { //2
t.notify(); //3
}
Object o = new Object();
System.out.println(null == o); //4
}
}


--------------------------------------------------------------------------------

A: The code does not compile due to line //1.
B: The code does not compile due to line //2.
C: The code does not compile due to line //3.
D: The code does not compile due to line //4.
E: There is nothing wrong with the code.

i answered d, since u r comparing null == o; but the correct answer is e.
can somebody plz explain.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have not gone through the code yet my request is use code tag for posting the code, it is available just below Add Reply button, that would be helpful for all, thanks.



A: The code does not compile due to line //1.
B: The code does not compile due to line //2.
C: The code does not compile due to line //3.
D: The code does not compile due to line //4.
E: There is nothing wrong with the code.

i answered d, since u r comparing null == o; but the correct answer is e.
can somebody plz explain.

 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


since u r comparing null == o


So, why I cannot do so?

Just like you will do this:

In such sense, either "true" or "false" will be printed to the standard output.

Nick
 
sanjeevmehra mehra
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there is nothing wrong with line 4. it is comparing two values.
null == o, it will return either true or false.
== is comparison operator.
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic