class Operator_test{
String one,two;
}
class Main2{
public static void main(String ar[])
{
Operator_test test=new Operator_test();
Operator_test test2=test;
Operator_test test1=new Operator_test();
test.one="XYZ";
test1.two="XYZ";
if(test==test2)
System.out.println("test and test2 are equal");
else
System.out.println("test and test2 are not equal");
}
}
Hi ,
I was just checking the function of == operator and wrote the above code .The thing i am confused is that
i am getting the output as "test and test2 are equal " ,== operator comapres the reference variabels
test and test2 (and the not the content ,"XYZ") which are not equal so why if condition is passing .
Thanks in advance