Results 1 to 5 of 5
  1. #1
    ras_oscar is offline Member
    Join Date
    Jun 2013
    Posts
    60
    Rep Power
    0

    Default Java implements modifier

    Was reading through the java learnint trail on classes and came across something I don't understand. The trail talks about declaring a class such as follows:

    class engine implements dynomometer
    {
    bla
    bla
    bla
    }

    and goes on to talk about the "mplements modifier"as a formal way of declaring a class interface. And then goes on to show examples of classes with fields and methods declared directly. What is the purpose of declaring an interface using the "implements" modifier? is this used when the methods are declared in a separate file to link the two together? Can I safely declare and define my methods and fields within each class?

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: Java implements modifier

    Huh? Its just plain English. The above reads "this engine class implements the dynomometer interface". There is no declaring going on at all, dynomometer is declared in its own source file.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    ras_oscar is offline Member
    Join Date
    Jun 2013
    Posts
    60
    Rep Power
    0

    Default Re: Java implements modifier

    for relatively simple classes that contain both fields and methods, can i safely ignore the "implements" modifier and just toss my methods and fields into the same file?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: Java implements modifier

    Quote Originally Posted by ras_oscar View Post
    for relatively simple classes that contain both fields and methods, can i safely ignore the "implements" modifier and just toss my methods and fields into the same file?
    I think you don't understand the ideas: a class or an interface is a type; a class has implementation 'details' while an interface hasn't. A class can only extend from exactly one other class whil it can implement zero or more interfaces. Syntactically speaking, the Java compiler compiles types (there can be at most one public type in a source file). Methods of a type have to be defined, lexically scoped, inside that type so you can't just 'toss' around the definition of methods.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: Java implements modifier

    Its not a modifier. Learn what interfaces are, you're asking meaningless questions here. If you don't need an interface, don't create one.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Protected access modifier in Java
    By bluepratz in forum New To Java
    Replies: 6
    Last Post: 08-04-2010, 11:08 AM
  2. implements java.util.Comparator<type>
    By finn in forum New To Java
    Replies: 2
    Last Post: 05-14-2010, 07:58 PM
  3. protected modifier ? Constructors
    By javanew in forum New To Java
    Replies: 6
    Last Post: 04-06-2010, 12:59 PM
  4. Replies: 24
    Last Post: 05-18-2009, 11:23 AM
  5. How to implements cryptation in a java
    By paul in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 06:06 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
  •