Why boolean in Java takes only true or false? Why not 1 or 0 also?

后端 未结 8 1144
太阳男子
太阳男子 2020-12-01 05:28

Is there any reason why Java booleans take only true or false why not 1 or 0 also?

8条回答
  •  醉酒成梦
    2020-12-01 05:43

    Even though there is a bool (short for boolean) data type in C++. But in C++, any nonzero value is a true value including negative numbers. A 0 (zero) is treated as false. Where as in JAVA there is a separate data type boolean for true and false.

提交回复
热议问题