• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

q from jiris.com

 
JayaSiji Gopal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • 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.
 
sanjeevmehra mehra
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • 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.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic