Compare two objects with .equals() and == operator

前端 未结 15 1221
礼貌的吻别
礼貌的吻别 2020-11-22 01:13

I constructed a class with one String field. Then I created two objects and I have to compare them using == operator and .equals() too

15条回答
  •  再見小時候
    2020-11-22 01:27

    IN the below code you are calling the overriden method .equals().

    public boolean equals2(Object object2) { if(a.equals(object2)) { // here you are calling the overriden method, that is why you getting false 2 times. return true; } else return false; }

提交回复
热议问题