System.out.println method for boolean value with String compilation error
843789Apr 21 2010 — edited Apr 21 2010Could anyone plz explain why this going to happen ?
why we need a bracket here for boolean in sysout, why it is not showing any compilation error ?
public class General {
public static void main(String[] args) {
String s1 = "Kamal";
String s2 = new String("Kamal");
String s3 = new String(s2);
String s4 = s1==s2; // compilation error here
System.out.println("s1==s2 : " + s1==s2 ); // expecting compilation error as above, but no compilation error here and in outputnot showing string 's1==s2'
System.out.println("s3==s2 : " + s3==s2); // same as above
System.out.println("s1==s3 : " + s1==s3); // same as above
System.out.println("s1==s2 : " + (s1==s2)); // this is working fine as expected
System.out.println("s3==s2 : " + (s3==s2));
System.out.println("s1==s3 : " + (s1==s3));
}
}
Output is :
false
false
false
s1==s2 : false
s3==s2 : false
s1==s3 : false