Understanding boolean data type – CSKC
Sign In

Search

Code Learning #JAVA#3850    siteicon   siteicon  

Understanding boolean data type

The java boolean data type declaration and its features.

Learning Objectives

  • Declaration and initialisation of boolean type.
  • Non-convertibility of boolean type to other types.

Source Code

TC++ #3850

Source Code

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test Java

Code Understanding

boolean b=true;
Here we declare boolean data type b which is assigned a true status. true in java is just a reserved word to be used as boolean literal. The opposite of this is false.

//int x=b;
This line has been commented. If we un-comment this the code will not run as boolean type can not be converted to other type

if(b) System.out.println(b);
The boolean type can be directly checked in if conditions without using any comparison operator.

if(b==true) System.out.println(b);
However the use of comparison operator with boolean type is also allowed.

 


Suggested Filename(s): BooleanType.java



Share

Created: 19-Mar-2018 23:51 | Updated: 19-Mar-2018 23:51|