Hey guys, I have a little bit confused on below code and output
Main
public class Main {
public static void main(String[] args) {
ClassA classA = new ClassA();
System.out.println("====== Before =====");
classA.checking();
System.out.println("===== After =====");
classA.checking();
}
}
Class A
public class ClassA {
boolean b = true;
public String checking() {
System.out.println("B value is " + b);
if (b = true) {
System.out.println("B is true");
b = false;
} else {
System.out.println("B is false");
}
return null;
}
}
Output
====== Before =====
B value is true
B is true
===== After =====
B value is false
B is true
Why the last line of value B in After will change from false to true ?