I am trying to figure out how this boolean expression is evaluated:
int i = 0;
boolean exp = i > 1 && counter();
In the following code:
public class Main {
static int num = 0;
public static boolean counter(){
num++;
if(num == 6){
return true;
}
return false;
}
public static void main(String[] args) {
//int i = 2;
int i = 0;
boolean exp = i > 1 && counter();
System.out.println(num); // 0
System.out.println(exp); // false
}
}
Since i = 0, i > 1 is false and counter() returns false. However, I'm confused because the value of static variable num doesn't change despite the counter() function being in the boolean expression:
exp = i > 1 && counter();
I was expecting the output to be
1
false
but it is
0
false
Why does counter() not seem to be called?