An interface is simply a definition of the way a class is expected to
"act". It's a collection of definition of methods each of which must be
implemented for a class to be said "implementing" that interface.
To create an implementation of an interface either you can write it
"implements" that interface and implement every single interface method,
or you can write it extends another class that implements the interface
and override those methods that must have custom implementation/behavior.
Luca.
gabriel ha scritto:
> Hi
>
[quoted text clipped - 18 lines]
>
> Gabriel
>My question is, how would i go about creating my own instance of this
>interface so that the API utilises my methods instead of the blank,
>skeleton ones already provided?
>Is it simply Public interface myInterface extends APIInterfaceCLassNAMe?
You probably want public myClass implements APIInterfaceName. And provide
actual implementations of all the methods. If you write an interface, you can
declare methods but not actually implement any of them.
>or is there some other method?
>As far as java goes i've always been a little hazey around the concept
>of interfaces, thus my confusion.
An interface is just a pure abstract class, with a slightly different syntax
for creating the subclass - you implement it rather than extending it.
Many frameworks provide both an interface and a convenience base class that
partially implements it and lets you override just the part you want to change
(like Swing's Action interface and AbstractAction class - you can implement
Action or extend AbstractAction, depending on your needs).
I haven't played with Robocode much, but I thought it did this as well - you
extend Robot (or AdvancedRobot) and override the methods that get called at
various events.
--
Mark Rafn dagon@dagon.net <http://www.dagon.net/>
Lew - 30 Oct 2006 01:06 GMT
>> My question is, how would i go about creating my own instance of this
>> interface so that the API utilises my methods instead of the blank,
>> skeleton ones already provided?
> You probably want public myClass implements APIInterfaceName.
"public MyClass ..."
Class names should start with an upper-case letter.
- Lew
Prasad - 01 Nov 2006 11:59 GMT
>>> My question is, how would i go about creating my own instance of this
>>> interface so that the API utilises my methods instead of the blank,
[quoted text clipped - 7 lines]
>
> - Lew
Starting class names with an upper-case letter, is a widely used (good)
convention. But I don't think it is required by the language.
The following code compiles and executes just fine.
public class sample
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}

Signature
Prasad