Hi
The interface methods are by default (and must only be )'public' and 'abstract'. The member variables are constants.
For example:
// This is what you code
interface Archnid{
String SOME_CONSTANT= "CONSTVALUE";
void bite();
void spinWeb(String s);
}
// This is what compiler make changes or adds to the above code.
// Note that the compiler added 'public' and 'abstract' access and non-access modifiers for the methods.
// Note also that the 'public', 'static' and 'final' access and non-access modifiers for the member variables
interface Archnid{
public static final String SOME_CONSTANT = "CONSTVALUE";
public abstract void bite();
public abstract void spinWeb(String s);
}
// This is when you implement the above interface
// Here you must specify the method signature as coderanch, if not compiler error occurs!
class ArchnidImpl implements Archnid{
public void bite(){
// your implementation code goes here...
}
public void spinWeb(){
// your implementation code goes here...
}
}
Bottom line is, the interface methods are by default(and must only be) 'public' and 'abstract'. Even if you specify or not, compiler adds it for you('public' and 'abstract' modifiers, as the example above)!
Interface can have only constants are member variables! Otherwise, compiler error occurs!
But when you implement an interface, you must specify the signature exactly. For example, void bite(){} is not the same as public void bite(){}. While implementing an interface, compiler will not add the necessary modifiers for you!
Hope it helps.
Kind Regards
Kris