What will be the output of the code snippet given below and why?
public static void main(String[] args) {
if (method()¦ method())
System.out.println("stmt1");
}
static boolean method() {
System.out.println("stmt2");
return true;
}
Send me the answer in your comment.
this line :
ReplyDeleteif (method() method())
isnt correct so an error is outputted...
if it was correct like:
if (method() == method())
the output is stmt1
Nothing will output.
ReplyDeleteI pipe symbol will not validate that code snippet either...
ReplyDeleteIs this a trick question or can you program in Java?
"The Ghost In Your Machine"-This snippet will definitely work. Try this out in your own IDE.
ReplyDeleteI think you're just asking what the difference is between | and ||, for which I implore you to look at the Java Language Specification, which covers it explicitly.
ReplyDeleteThis isn't a tricky question, it's very basic Java.