Java Reference
In-Depth Information
class Test extends Applet implements Runnable {
...
public void run () {
...
}
}
public interface Runnable {
public void run ();
}
To implement multiple interfaces, just separate the interface names with a
comma:
class Test extends Applet implements Runnable, AnotherInterface
{
...
}
If two interfaces each define a method with the same name and parameter list,
this presents no ambiguity since both methods are abstract and carry no code
body. In a sense, both are overridden by the single method with that signature in
the implementing class.
Any class that implements an interface can be referenced as a type of that
interface, as illustrated by this code:
class User implements Runnable {
public void run () {
...
}
}
class Test {
public static void main (String[] args) {
Runnable r = new User ();
...
}
}
Here the class User implements Runnable ,soitcan be referenced in a variable
of type User or in a variable of type Runnable as shown. The value of using
the type Runnable instead of User is illustrated in the next section.
Search WWH ::




Custom Search