wellnwill Marathahalli Bangalore

Relational Operators

  • Relational Operators are used to check relation between two variables or numbers.
  • Relational Operators returns “Boolean” value .i.e. true or false.

Operator Result
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
  • We can not apply relational operator for boolean and reference types.
  • Listing of relational operator is not allowed.

class Test42
{
  public static void main(String argss[])
  {
    System.out.println(10>20);  
    System.out.println('a'>10);  // ASCII of a is 97.
    System.out.println(10!=10); 
   }
}

// O/P - false,true,false


class Test43
{
  public static void main(String argss[])
  {
    Test43 t=null;
    String s=null;
    System.out.println(t==s);   
  }
}


// O/P - CompileTimeException 
       - incomparable types : Test43 and String
Note - no relation b/w Test43 and String.
class Test44
{
  public static void main(String argss[])
  {
    System.out.println(10>20>30);//listing of operators   
  }
}

// O/P - CompileTimeException 
       - bad operand types of binary operator ’>
	   
	   
class Test044
{
   int id;
   public static void main(String argss[]){
   Test044 t1=new Test044();
   Test044 t2=new Test044();
   System.out.println(t1==t2);   
   System.out.println(t1.id==t2.id);   
  }
}


//o/p - false
Footer with Map

Top