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

Поделиться
HTML-код
  • Опубликовано: 6 ноя 2024

Комментарии • 40

  • @Egganopolis82
    @Egganopolis82 2 года назад +5

    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!

  • @Appficial
    @Appficial  5 лет назад +3

    Please SUBSCRIBE! More programming videos coming soon! ✌️

  • @asht7788
    @asht7788 4 года назад +6

    Thank you, I wish professors explained it this simple.

    • @Appficial
      @Appficial  4 года назад +5

      Thanks I actually am a professor 👍

  • @sebahalabi6239
    @sebahalabi6239 Год назад +2

    thank you so match (يسعدلي الشارب)

  • @alexcondon1116
    @alexcondon1116 4 года назад +2

    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?

    • @Appficial
      @Appficial  4 года назад +2

      Hi, it's because the parameter is Object, and in order for java to know that the type of that object is Student, then you cast it to covert it to a Student object. This allows you to call Student methods

    • @alexcondon1116
      @alexcondon1116 4 года назад +3

      ​@@Appficial Thank you for the explanation. My professor has not gone over the Object keyword yet, so this cleared up a lot of confusion.

    • @Appficial
      @Appficial  4 года назад +1

      @@alexcondon1116 you're welcome. Don't forget to subscribe and tell your classmates about appficial 👍

    • @jorge5208
      @jorge5208 2 года назад +1

      @@Appficial Couldn't we use in our if statement the operator instanceof, for example, in each if (or a bigger if in case we use && for each condition) can't we put obj instanceof Student?

    • @Appficial
      @Appficial  2 года назад +2

      @@jorge5208 yea that's another way to do it

  • @sumonadas3640
    @sumonadas3640 3 месяца назад +1

    LOve your demonstration

  • @Rockyzach88
    @Rockyzach88 Год назад +1

    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.

    • @Sandeep-od1uc
      @Sandeep-od1uc Год назад

      thats because private is a class level.

  • @medinasFamily
    @medinasFamily 4 года назад +4

    great explanation and easy to follow.

  • @SafeinKyroh
    @SafeinKyroh 4 года назад +3

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

    • @Appficial
      @Appficial  4 года назад +3

      If you are in the class where you declared name, then no need to call getName() since you have direct access to that variable

    • @SafeinKyroh
      @SafeinKyroh 4 года назад +1

      @@Appficial thank you!

  • @28santagabo
    @28santagabo 4 месяца назад +1

    super helpful! thanks

  • @supernovic99
    @supernovic99 Год назад +1

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

    • @Appficial
      @Appficial  Год назад

      Thanks!

    • @supernovic99
      @supernovic99 Год назад +1

      @@Appficial I'm actually self studying for the APCSA exam. Inheritance was kind of hard and confusing(too theoretical) but your videos really align to the concepts I found hard. Have a great day!

    • @Appficial
      @Appficial  Год назад

      @@supernovic99 good luck on the exam. Glad my videos help!

  • @kassemdarawcha1476
    @kassemdarawcha1476 2 года назад +1

    Thank yuo professoer

  • @manpreetkaur5568
    @manpreetkaur5568 2 года назад +1

    Thanks a lot. Very helpful

  • @challuri1
    @challuri1 4 года назад

    how to find earlier class link

  • @rejuyanahmed2947
    @rejuyanahmed2947 2 года назад

    It was helpful. thank you sir.

  • @leekbiel
    @leekbiel 2 года назад +1

    Thanks!!!!!

  • @conforzo
    @conforzo 2 года назад +1

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

    • @Appficial
      @Appficial  2 года назад

      It compares content for String but for other objects it compares reference unless you override the method to compare content

  • @aq6910
    @aq6910 Год назад

    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.

    • @Appficial
      @Appficial  Год назад +1

      If an equals method is in a Student class, then it's expected to only pass Student objects to it. Its bad programming to pass a nonstudent object to it, so my implementation is not wrong, but your method call is actually wrong.

  • @WiiHack
    @WiiHack 4 года назад

    Danke
    ANGRIFF

  • @anupam5886
    @anupam5886 Год назад

    Nin thika

  • @mrpipiskin4
    @mrpipiskin4 2 года назад +1

    ааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааааа