+ 1
Can anyone help me with this code
public class Program { public static void main(String[] args) { System.out.println("main starts"); boolean boolval; if(boolval=true){ System.out.println(boolval) ; } System.out.println(boolval); } } I did not assign boolval to true,yet output shows true.how is this possible?
2 Answers
+ 2
You need to use == to compare. Otherwise, it will set boolval to true.
+ 2
Ajoh Pv You need to know the difference between = and ==
= is assignment operator
== equality check operator means comparison operator.
So boolval = true means you are assigning which will be true. That's why it's going in if statement and returns true.