Difference between revisions of "Interfaces"
From Suhrid.net Wiki
Jump to navigationJump to search (Created page with "* All interface methods are implicitly '''public and abstract''' * Even if some modifiers are left out, the above modifiers will be applied. * Since they have to be overriden,'''...") |
|||
Line 27: | Line 27: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | [[Category:OCPJP]] |
Revision as of 00:27, 22 August 2011
- All interface methods are implicitly public and abstract
- Even if some modifiers are left out, the above modifiers will be applied.
- Since they have to be overriden, methods cannot be static.
- Similarly they cannot be final, strictfp, or native.
- All variables are implicitly public, static and final
- Even if some modifiers are left out, the above modifiers will be applied.
- Since variables are final, they must be initialized
- If no access modifier is specified, the member is public, not package !
- Similarly, specifying protected/private is not allowed for methods and variables
- Watch out when classes implement interfaces and don't specify the method as public - this wont compile.
- Similarly, watch out when classes try to reassign the value of an interface.
- Note, the interface itself can be public OR package accessible, but members get default public access as described above.
public interface Mashable {
public int COUNT; //illegal not initialized !
int MINCOUNT = 3; //this is public, static and final implcitly.
public static final int MAXCOUNT=10; //full correct declaration
void foo(); //Implicity: public abstract void foo();
static void foo(); //Illegal;
}