troubleshooting Question

interface java.util.Comparator

Avatar of chrisdtrinityphysicians
chrisdtrinityphysiciansFlag for India asked on
Java
1 Comment1 Solution396 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
ksivananth
Vice President

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros