'boolean' variable can only hold one of two possible values, true or false.
Program demonstrating the boolean type:
class BoolTest1
{
public static void main(String args[])
{
boolean b=false;
System.out.println(" b is " +b);
b=true;
System.out.println(" b is " +b);
}
}
Output of this program:
b is false
b is true
Program demonstrating that a boolean value can control the if statement
class BoolTest2
{
public static void main(String args[])
{
boolean b=true;
if(b)
System.out.println("This is executed");
b=false;
if(b)
System.out.println("This is not executed");
}
}
Output of this program:
This is executed
Program demonstrating that the outcome of a relational operator is a boolean value
class BoolTest3
{
public static void main(String args[])
{
System.out.println("10 > 9 is "+(10>9));
}
}
Output of this program:
10 > 9 is true