Results 1 to 8 of 8

Thread: Interfaces

  1. #1
    Join Date
    Dec 2007
    Posts
    8
    Rep Power
    0

    Default Interfaces

    Hi,

    Can you tel me more about interfaces & in what applications can we implement that concept..

  2. #2
    Corvin's Avatar
    Corvin is offline Member
    Join Date
    Dec 2007
    Location
    Germany
    Posts
    2
    Rep Power
    0

  3. #3
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

    Default

    Interfaces can be used to tell in implementing class that it NEEDS to have those methods implemented. Since java does not support multiple inheritance (ie. extend more than one object) it is usefull to tell something it needs to conform to a certain standard.

    Basicly, lets say you create an interface with a single method void called foo(). In interfaces, methods cannot have bodies, so it will look something like:
    Java Code:
    public interface FooInterface {
    	public void foo();
    }
    Then in your class you can do:
    Java Code:
    public class BarClass implements FooInterface {
              
    }
    If you tried to compile something like this it will give you an error, because you need the foo() method.

    Java Code:
    public class BarClass implements FooInterface {
              public void foo() {
                        // blah
              }
    }
    I use interfaces mostly when i am creating a complicated class/sublass structure, and want all my code to conform to a certain standard.
    A plugin system would be an example of using interfaces.

  4. #4
    Join Date
    Dec 2007
    Posts
    8
    Rep Power
    0

    Default Thank u..

    can you suggest me any small real time application on which i can do a project in core Java..

  5. #5
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    Kavana, try creating a new thread instead of spamming old threads. In that way, you can find better answers if you select appropriate thread titles.

  6. #6
    Join Date
    Dec 2007
    Posts
    8
    Rep Power
    0

    Unhappy Is it a disadvantage of interface?

    It was given as,
    A class which implements an interface must either implement all methods in the interface, or be an abstract class.
    - since a class which implements an interface has to implement all the methods of that interface, is it not a disadvantage that it has to implement all methods even if we want only some methods to be implemented..

  7. #7
    Join Date
    Dec 2007
    Posts
    8
    Rep Power
    0

    Default

    i did not understand what you told sir.. did you mean that i should post my queries directly than just replying to their replies.. i am new to this forum so am not much familiar how to use..

  8. #8
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    did you mean that i should post my queries directly than just replying to their replies..
    Yes! Your query below is not related to this thread. Go to appropriate forum index and click "New Thread" button, instead of clicking to the "Post Reply" button here.

    can you suggest me any small real time application on which i can do a project in core Java..

Similar Threads

  1. interfaces..
    By sireesha in forum New To Java
    Replies: 5
    Last Post: 01-16-2008, 05:52 PM
  2. Using interfaces with Delegation
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-06-2007, 01:49 PM
  3. Help, someone clear up Interfaces for me
    By mathias in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 02:26 AM
  4. Interfaces
    By imran_khan in forum New To Java
    Replies: 5
    Last Post: 07-30-2007, 08:11 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
  •