Results 1 to 5 of 5

Thread: Interfaces

  1. #1
    marcvaf is offline Member
    Join Date
    Jan 2014
    Posts
    6
    Rep Power
    0

    Default Interfaces

    Hi,

    Looking at a question for the programmer 1 exam :

    interface Rideable {
    String getGait();
    }

    public class Camel implements Rideable
    {
    int weight = 2;

    public static void main(String[] args)
    {
    new Camel().go(8);
    }

    void go(int speed)
    {
    ++speed;
    weight++;
    int walkrate = speed * weight;
    System.out.print(walkrate + getGait());
    }

    String getGait()
    {
    return " mph, lope";
    }

    }

    What is the result?
    A) 16 mph, lope
    B) 18 mph, lope
    C) 24 mph, lope
    D) 27 mph, lope
    E) Compilation fails.
    F) An exception is thrown at run time.


    The Answer is compilation fails due to

    cannot implement getGait() in Rideable; attempting to assign weaker access privileges; was public


    but if i make String getGait public it works, my question is what is getGait() set as default? Been looking and cant seem to find the answer.

    thanks

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

    Default Re: Interfaces

    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    marcvaf is offline Member
    Join Date
    Jan 2014
    Posts
    6
    Rep Power
    0

    Default Re: Interfaces

    thanks will take a look

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

    Default Re: Interfaces

    No problem. And a tip: the next time copy/paste the compilation error into Google and see what you get. Usually within the first five hits you will find a forum post that is exactly your question, with the answers.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,030
    Rep Power
    6

    Default Re: Interfaces

    I think what the OP really wants is here --> Defining an Interface (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)
    Under the section "Interface Body."

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Interfaces
    By blobbyx22 in forum New To Java
    Replies: 4
    Last Post: 11-27-2011, 11:35 AM
  2. Interfaces (not GUI)
    By guilty in forum Advanced Java
    Replies: 1
    Last Post: 11-05-2010, 08:16 PM
  3. Interfaces
    By justin1980 in forum New To Java
    Replies: 9
    Last Post: 02-10-2010, 01:04 PM
  4. Interfaces
    By computerquip in forum New To Java
    Replies: 19
    Last Post: 09-08-2009, 05:58 PM
  5. Interfaces
    By imran_khan in forum New To Java
    Replies: 5
    Last Post: 07-30-2007, 09: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
  •