Results 1 to 5 of 5

Thread: Interface?

  1. #1
    MarkWilson is offline Member
    Join Date
    Jun 2008
    Location
    us
    Posts
    47
    Rep Power
    0

    Default Interface?

    can we define Interface inside the class? if yes whts it use & how

    or

    can we define class inside interface ? if yes whts it use & how

    please clear my this point with some example


    Thank'x
    Last edited by MarkWilson; 07-11-2008 at 01:31 PM.

  2. #2
    Niveditha's Avatar
    Niveditha is offline Senior Member
    Join Date
    May 2008
    Posts
    307
    Rep Power
    7

    Default

    Hi,
    I think you dont know anything about interfaces, why don't you go through some example in the internet by doing a google search.

    Coming to your question, No neither interface can be defined in class nor the vice versa.

    An interface has only method and variable definitions which can be implemented by any java class by using "implements" clause.
    To finish sooner, take your own time....
    Nivedithaaaa

  3. #3
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default yep

    An interface only declares methods, one has to implement the methods in a class.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

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

    Default

    An interface is a way to make an object a specific type so that you can pass that object to a method that wants that type as an arg.
    For example the Thread class wants an arg of type Runnable. You can have ANY of your classes be of type Runnable by having the class implement Runnable.
    Then you have to look at the doc for the interface Runnable, see what methods it requires and write those methods in your class.
    In this case, the only method is: public void run() {...

    Basically interface is a way to use types to define classes and their methods.

  5. #5
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default good marks for navigator

    Quote Originally Posted by Norm View Post
    An interface is a way to make an object a specific type so that you can pass that object to a method that wants that type as an arg.....
    I just saw a good one in Java Tips, how to have an interface extend an interface.

    Nowhwere in all of java docs will it show how to do this.

    ( I realize that is not what poster asked )
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Similar Threads

  1. Implementing Interface
    By mew in forum New To Java
    Replies: 4
    Last Post: 02-16-2010, 03:33 PM
  2. Need help with Document interface
    By cbalu in forum AWT / Swing
    Replies: 1
    Last Post: 11-30-2007, 11:03 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
  •