Forum

Number Of Page View:100,000+/Months
LOGIN |New User

Reply

Equality for Reference Variables
We already know about two reference variables can refer to the same object, we have a example :
Button a = new Button("Exit");
Button b = a;
     When its execute both of variables are refer same object , Reference variable also test to the they refer same object using == operator.

import java.awt.Button;
class CompareReference {
public static void main(String [] args) {
Button a = new Button("Exit");
Button b = new Button("Exit");
Button c = a;
System.out.println("Is reference a == b? " + (a == b));
System.out.println("Is reference a == c? " + (a == c));
}
}
            This code creates three reference variables. The first two, a and b, are separate
Button objects that happen to have the same label. The third reference variable, c, is
initialized to refer to the same object that a refers to. When this program runs, the following output is produced :
 
    Is reference a == b? false
    Is reference a == c? true
Posted By: Name:Rajesh Kr URL: Equality for Reference Variables