Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Interface

  1. #1
    Member
    Join Date
    Jul 2012
    Posts
    90
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Interface

    Hello,i have two beginner's questions.
    1- Can an interface have some fields(i mean variables)?Or the only thing it contains are prototypes of methods?
    2-When we want a method to receive no arguments at all how do we state it?I tried to write void,but the compiler says <identifier> expected
    Here is the code
    package airplane;
     
    public interface AirplaneInterface {
        boolean taxi(String taxiway);
        boolean takeoff(String runway);
        boolean approach(String runway);
        boolean land(String runway);
        void setEngines(boolean on);
        boolean changeAltitude(int factor);
        int getAltitude(void);
    }


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Interface

    Quote Originally Posted by Samaras View Post
    Hello,i have two beginner's questions.
    1- Can an interface have some fields(i mean variables)?Or the only thing it contains are prototypes of methods?
    2-When we want a method to receive no arguments at all how do we state it?I tried to write void,but the compiler says <identifier> expected
    1- What does the doc say about an interface? Read this page.
    2- When you declare a method with no arguments in a normal class do you write void in the parentheses? Try treating the method declaration like a method declaration in any other class.

  3. #3
    Member
    Join Date
    Jul 2012
    Posts
    90
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: Interface

    1- I am reading the tutorial you linked me,however i do not have reached the point you posted.But there lies this:
    In the Java programming language, an interface is a reference type, similar to a class, that can contain only constants, method signatures, and nested types.

    2 - I am new in JAVA and i did not think about it until i got to deal with it.Ok,thanks

Similar Threads

  1. [SOLVED] Cloneable interface
    By urpalshu in forum Object Oriented Programming
    Replies: 2
    Last Post: October 28th, 2011, 01:46 PM
  2. Help with Comparable interface.
    By novice564 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 19th, 2011, 08:39 AM
  3. Interface
    By kaasi in forum Member Introductions
    Replies: 4
    Last Post: April 21st, 2011, 10:45 AM
  4. interface
    By nasi in forum Object Oriented Programming
    Replies: 5
    Last Post: September 2nd, 2010, 10:36 PM
  5. Need Help on the Interface Function
    By yel_hiei in forum Object Oriented Programming
    Replies: 12
    Last Post: July 29th, 2010, 07:27 AM