Results 1 to 4 of 4
  1. #1
    john83 is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Default Ways of implementing interface

    What is the difference between implementing interface with keyword 'implements' and:

    Java Code:
    .... 
    interface_name object_name = new interface_name() {
          public void method_name(Object o) {
          .....
    Thanks in advance.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Ways of implementing interface

    What you have there is called an anonymous class. Take a look at the following link to see the restrictions on anonymous classes: Anonymous Classes (Java in a Nutshell)
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    john83 is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Default Re: Ways of implementing interface

    Thank you for your answer.

    I would like to know why is it used this in such way?

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Ways of implementing interface

    Quote Originally Posted by john83 View Post
    I would like to know why is it used this in such way?
    I don't really understand the question. It is used that way because that is how you used it.

    The link I gave you lists several situations where anonymous inner classes are useful.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. NEED HELP in IMPLEMENTING A GIVEN INTERFACE!
    By wasiqjaved in forum New To Java
    Replies: 0
    Last Post: 10-03-2011, 12:40 PM
  2. Implementing Interface
    By mew in forum New To Java
    Replies: 4
    Last Post: 02-16-2010, 03:33 PM
  3. help! implementing an interface
    By manda147 in forum New To Java
    Replies: 28
    Last Post: 11-17-2008, 04:27 AM
  4. Implementing an interface
    By bugger in forum Advanced Java
    Replies: 1
    Last Post: 01-09-2008, 01:35 PM
  5. Implementing Serializable interface
    By javaplus in forum Advanced Java
    Replies: 4
    Last Post: 12-18-2007, 12:29 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
  •