Hello Sarim,
if() in
java takes boolen value. boolean value in java are true and false. C & C++ programmer have to be careful as in that boolean could also take numerical values...where 0 mean false and 1 mean true. Why i am saying is that in the parentheses of if statement you could either directly put boolean value or an expression.
so when you say if(a=true)....here a=true is an expression result of which is boolean value that is true.
Where as in c & c++ we could use expression which could evaluate to 0 (false) and 1 (true).
So while going through the code given in exam be careful of seeing that if it is = or == operator.
Hope things are clear to you now.
Chek the following code:
class Test {
public static void main(
String [] args) {
boolean flag = false;
if (flag=true)
System.out.println("Hello Java");
else
System.out.println("Hello Sarim");
}
}
check the output.
Regards,
Raj.