Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static method

 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this question in Marcus Green mock exam:

public class Ombersley{
public static void main(String argv[]){
boolean b1 = true;
if((b1 ==true) || place(true)){
System.out.println("Hello Crowle");
}
}

public static boolean place(boolean location){
if(location==true){
System.out.println("Borcetshire");

}
System.out.println("Powick");

return true;
}
}

The answer is Hello Crowle
Would anyone pls explain, is that b/c the static boolean method.
Thanks
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jay lai:
...The answer is Hello Crowle
Would anyone pls explain, is that b/c the static boolean method...

It's because of the short-circuiting "or" ( || ).

(b1==true) evaluates to true, and so place(true) is not evaluated.

Does that make sense?
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes: it does
thanks for response.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic