Overriding the Object equals Method - Java Override Example - Comparing Objects - APPFICIAL

preview_player
Показать описание
equals() is a method that comes from the Object class. Equals compares the calling object with another object and returns true if they are equal, or false otherwise. You typically override this method if you want to compare two objects of a class you created.

Subscribe!
Рекомендации по теме
Комментарии
Автор

This was super helpful for me. I was getting confused on how to implement an Override equals method from scratch and this just cleared up all of my questions. Thank you!

Egganopolis
Автор

Thank you, I wish professors explained it this simple.

asht
Автор

Please SUBSCRIBE! More programming videos coming soon! ✌️

Appficial
Автор

Just to make sure I'm not missing something. Since the StudentID field is private, don't you need a public getter to get it from the argument object instead of dotting it? However it works for you.

EDIT: Nevermind, it's because they share the same class. I was thinking that encapsulation worked cross object too but no.

Rockyzach
Автор

These videos are amazing!!! Thank you so much!

supernovic
Автор

Hi, I'm taking a java course at my University. This video has cleared things up quite a bit. I just have one question though, I am having trouble understanding why you would need to cast the object into a (Student)? What is the reason for this?

alexcondon
Автор

Hi, how come in the if statement we used s.getName() instead of just s.name [s.name.equals(this.name)]

SafeinKyroh
Автор

I thought we used to equals method just because we compare the content instead of the reference.

conforzo
Автор

your implementation is wrong if we pass a value which is not an instance of Student we get an error, same if we pass null.

aq