javacodex.com
Java Examples
Java Examples
memu home questions

Equality Reference Variables

This java program example demonstrates the use of equality operators on reference variables.

Source: (EqualityReference.java)

public class EqualityReference {
   public static void main(String[] args) {
 
      EqualityReference er1 = new EqualityReference(); 
      EqualityReference er2 = new EqualityReference();
      EqualityReference er3 = er2;
 
      boolean a = er1 == er2;
      boolean b = er1 == er3;
      boolean c = er2 == er3;
 
      System.out.println("a = " + a );
      System.out.println("b = " + b );
      System.out.println("c = " + c );
   }
}
 

Output:

# java EqualityReference 
a = false
b = false
c = true

Contact: javacodex@yahoo.com