Abstract class error in java -
i'm trying figure out why keep getting error class not override abstract method. in teachers uml diagram shows need equals (object o) method in parent radio class. i'm not declaring abstract in abstract class.
public abstract class radio implements comparable { double currentstation; radioselectionbar radioselectionbar; public radio() { this.currentstation = getmin_station(); } public abstract double getmax_station(); public abstract double getmin_station(); public abstract double getincrement(); public void up() { } public void down() { } public double getcurrentstaion() { return this.currentstation; } public void setcurrentstation(double freq) { this.currentstation = freq; } public void setstation(int buttonnumber, double station) { } public double getstation(int buttonnumber) { return 0.0; } public string tostring() { string message = ("" + currentstation); return message; } public boolean equals (object o) { if (o == null) return false; if (! (o instanceof radio)) return false; radio other = (radio) o; return this.currentstation == other.currentstation; } public static void main(string[] args) { radio amradio = new amradio(); system.out.println(amradio); radio fmradio = new fmradio(); system.out.println(fmradio); radio xmradio = new xmradio(); system.out.println(xmradio); } } public class amradio extends radio { private static final double max_station = 1605; private static final double min_station = 535; private static final double increment = 10; public amradio() { currentstation = min_station; } public double getmax_station() { return this.max_station; } public double getmin_station() { return this.min_station; } public double getincrement() { return this.increment; } public string tostring() { string message = ("am " + this.currentstation); return message; } }
you have implement compareto()
method, given radio
implements comparable
interface , concrete implementation method wasn't provided in radio
class, have 2 choices:
- implement
compareto()
in ofradio
's subclasses - or implement
compareto()
inradio
something this, in amradio
:
public int compareto(amradio o) { // return appropriate value, read linked documentation }
or this, in radio
:
public int compareto(radio o) { // return appropriate value, read linked documentation }
Comments
Post a Comment