Avatar of chrisdtrinityphysicians
chrisdtrinityphysicians
Flag for India asked on

interface java.util.Comparator

Hi,

      I am new to java (basically I am a C#.Net guy). I extracted the java.util.Comparator interface. There I can see two abstract methods (1) public abstract int compare(java.lang.Object arg0, java.lang.Object arg1); and (2) public abstract boolean equals(java.lang.Object arg0);. I implemented this interface in MyClass and it is working fine.

My Question is:
*************

      By normal OOPs rule, we should define all the abstract methods which are available in interface at the time of implementation.
       But here we have 2 abstract methods (compare and equals) and I am implementing only campare method. I just ignored the equals methods. But I am not getting any compilation or run-time error.
       At the same time, if I not implement the method compare, I am getting compilation error.

       What is the difference between the abstract methods compare and equals? Why "compare" method only mandatory? Please explain to me
Java

Avatar of undefined
Last Comment
ksivananth

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ksivananth

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes