Results 1 to 6 of 6

Thread: Interface issue

  1. #1
    vermio is offline Member
    Join Date
    Jul 2010
    Posts
    8
    Rep Power
    0

    Default Interface issue

    Hi,

    Does anyone knows what's wrong with this one?
    It produces the following errors
    OperateCar.java:15: OperateBMW760i is not abstract and does not override abstract method getRadarRear(double,double) in OperateCar
    class OperateBMW760i implements OperateCar {
    ^
    OperateCar.java:16: signalTurn(Direction,boolean) in OperateBMW760i cannot implement signalTurn(Direction,boolean) in OperateCar; attempting to assign weaker access privileges; was public
    int signalTurn(Direction direction, boolean signalOn) {
    ^
    2 errors


    What does this error mean?

    I get the program from here:
    Interfaces (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    The messages are mostly in English and if you read them they'll tell you what is wrong.
    does not override abstract method getRadarRear(double,double)
    The class does extends an abstract class and does not override abstract method getRadarRear(double,double)
    Add an override to that method to your class.

    attempting to assign weaker access privileges; was public
    Add public to the method definition.

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    806
    Rep Power
    6

    Default

    1.In the first case..you should override all the methods of interface if the extending class is not abstract.

    2.u can't give weaker access for interface methods.
    Ramya:cool:

  4. #4
    vermio is offline Member
    Join Date
    Jul 2010
    Posts
    8
    Rep Power
    0

    Default

    Sorry guys, I forget to enclose the code.
    I changed it a little bit but I still have the same issue.
    Here it is:

    enum Direction {
    RIGHT, LEFT
    }
    interface OperateCar {

    // constant declarations, if any

    // method signatures

    int getRadarFront(double distanceToCar, double speedOfCar);
    int GetInterface(OperateCar other);
    }

    public class OperateCar01 implements OperateCar
    {
    public int SignalTurn(Direction direction, boolean SignalOn)
    {
    int o = 1;
    return o;
    }
    public int GetInterface(OperateCar other)
    {
    //OperateCar OtherCar = (OperateCar)other;
    return 0;
    }
    }


    The line that cannot be compiled is the red one.
    Error:
    OperateCar01 is not abstract and does not override abstract method getRadarFront(double,double)

    How can I declare it to pass?
    Which methods are abstract and which are not?
    Thanx and sorry for my ignorance.:D

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    OperateCar01 ... does not override abstract method getRadarFront(double,double)
    This part of the error message tells you what you must do.
    You overrode getInterface() Ok. Now override getRadarFront()

  6. #6
    vermio is offline Member
    Join Date
    Jul 2010
    Posts
    8
    Rep Power
    0

Similar Threads

  1. Is there a GUI interface for...
    By smith427 in forum New To Java
    Replies: 3
    Last Post: 12-03-2009, 07:17 AM
  2. what is the need of interface?
    By makpandian in forum New To Java
    Replies: 1
    Last Post: 03-13-2009, 10:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •