Let's see the following simplest code snippet in Java.
final public class Parsing
{
public static void main(String[] args)
{
int p=10;
int q=10;
System.out.println(p==q);
}
}
The above code in Java is fine and displays true as both p and q of the same type (int) contain the same value (10). Now, I want to concatenate the argument of println() so that it contains a new line escape sequence \n and the result is displayed in a new line as below.
System.out.println("\n"+p==q);
Which is not allowed at all because the expression p==q evaluates a boolean value and a boolean type in Java (not Boolean, a wrapper type) can never be converted to any other types available in Java. Therefore, the above mentioned statement is invalid and it issues a compile-time error. What is the way to get around such situations in Java?
and surprisingly, the following statements are perfectly valid in Java.
System.out.println("\n"+true);
System.out.println("\n"+false);
and displays true and false respectively. How? Why is the same thing in the statement System.out.println("\n"+p==q);
not allowed?