Results 1 to 7 of 7

Thread: Interface

  1. #1
    qadeer37 is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default Interface

    interface Cricket
    {
    public void Pitch (String type);
    public void Seats (int num);
    }


    class Arrangement implemets Cricket
    {



    public void Pitch (String types);
    {
    System.out.println (types);
    }


    public void Seats (int nums)
    {
    System.out.println (nums);
    }
    }


    public Class Match
    {
    public static void main (String arg)
    {
    Arrangement arg = new Arrangement ();

    arg.Pitch ("fast");
    arg.Seats (4000);
    }
    }

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

    Default

    Yes?

    kind regards,

    Jos

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Apart from the use of "public" in the interface methods, that is indeed an example of an interface.

  4. #4
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    public void Pitch (String types); There is no semicolon after the method header in the class Arrangement. This novice mistake could have been easily avoided if the code was lucid.

    This is how it should be. Next time, please put your code in [code] tags.

    Java Code:
    interface Cricket {
    	public void Pitch (String type);
    	public void Seats (int num);
    }
    Java Code:
    class Arrangement implements Cricket {
    
    	public void Pitch (String types) {
    		System.out.println (types);
    	}
    
    
    	public void Seats (int nums) {
    		System.out.println (nums);
    	}
    }
    Last edited by Lil_Aziz1; 02-01-2010 at 11:42 PM.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Still don't need the "public" there...

  6. #6
    Turtle is offline Member
    Join Date
    Nov 2007
    Location
    New Zealand
    Posts
    36
    Rep Power
    0

    Default

    @Tolls: I can see why you have 745 posts :-)
    But he's right, interfaces are implicitly public and abstract. (MyPosts++ :-P)

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

Similar Threads

  1. Is there a GUI interface for...
    By smith427 in forum New To Java
    Replies: 3
    Last Post: 12-03-2009, 08:17 AM
  2. How do I use an Interface for this?
    By aaronfsimons in forum New To Java
    Replies: 14
    Last Post: 06-22-2009, 03:19 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
  •