0

As I said in title, I'm creating a parent class implementing Comparable interface in it but without implement compareTo() method and this is causing an error in child classes but not in Parent class ¿Why?

This is a sample:

public abstract class EarthquakeMarker extends CommonMarker implements Comparable<EarthquakeMarker>
{
// I know that I need to implement compareTo() here
}

My child classes are:

public class LandQuakeMarker extends EarthquakeMarker {
}

public class OceanQuakeMarker extends EarthquakeMarker {
}

Both child classes are complaining about the implementation of compareTo() method. I want to know why this error appears in child classes instead of the parent class which is the class that's using the comparable interface

Juan David
  • 2,676
  • 4
  • 32
  • 42
  • You need it, because, and I assume, you have to just out the two child classes within the parent class. No more problem. Once you've used your constructor, it'll use everything in that class by inheritance – David Pulse Oct 16 '15 at 01:15
  • 1
    Abstract class doesn't need to implement anything, it is like interface, but with the difference, that you can provide some implementation in it. Your abstarct class decalres that it have some intarface, but is not obligated to provide default implementation for it, but descendatnt non-abstarct classes are obligated to give implementation for any method that is declared by Abstract class and doesn't have default implementation, like with normal interface. – Krzysztof Cichocki Oct 16 '15 at 08:30

0 Answers0