Mega Code Archive

 
Categories / Java Book / 001 Language Basics
 

0022 Boolean Literals

Boolean literals are only two logical values: true and false. The values of true and false do not convert into any numerical representation. The true literal in Java does not equal 1, nor does the false literal equal 0. In Java, they can only be assigned to variables declared as boolean. public class Main { public static void main(String[] argv) { boolean b = true; int i = b; } } If you try to compile the program, the following error message will be generated by compiler. Main.java:5: incompatible types found : boolean required: int int i = b; ^ 1 error