Results 1 to 3 of 3
  1. #1
    Crakrjack is offline Member
    Join Date
    Sep 2013
    Posts
    20
    Rep Power
    0

    Default Creating methods in implemented class not in interface.

    I have an interface that I am implementing, and I've added a method that is not defined in the interface.
    When i try to use the method from main, I get the following error in Eclipse.
    Java Code:
    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    	The method setIsChosen() is undefined for the type Road
    
    	at assign2.Driver.main(Driver.java:20)
    Does anyone know the reason for this error?

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,340
    Rep Power
    5

    Default Re: Creating methods in implemented class not in interface.

    You can't add a new method to an interface implementation and then reference that method from an instance of the interface. It has to be a reference to the implementation.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Crakrjack is offline Member
    Join Date
    Sep 2013
    Posts
    20
    Rep Power
    0

    Default Re: Creating methods in implemented class not in interface.

    Thanks again Jim, all sorted now.

Similar Threads

  1. Creating objects for class and referenced to interface
    By mkarthik90 in forum New To Java
    Replies: 3
    Last Post: 07-25-2013, 12:43 PM
  2. Replies: 1
    Last Post: 07-08-2012, 05:23 PM
  3. Can an Interface have implemented method???
    By pppriyadarshi in forum New To Java
    Replies: 1
    Last Post: 09-10-2011, 06:44 PM
  4. How should an Animation class be implemented?
    By kiregad in forum New To Java
    Replies: 9
    Last Post: 06-18-2010, 07:39 AM
  5. Class Reflection: Finding implemented interfaces
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:09 PM

Posting Permissions

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