interface java.util.Comparator

chrisdtrinityphysicians
chrisdtrinityphysicians used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
the equals method is already implemented part of Object class which by default all classes extend implicitly. so you don't have to implement it separately.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial