Mega Code Archive

 
Categories / Java Book / 002 Class
 

0160 Defining an Interface

An interface is defined much like a class. This is the general form of an interface: access interface name { return-type method-name1(parameter-list); return-type method-name2(parameter-list); type final-varname1 = value; type final-varname2 = value; // ... return-type method-nameN(parameter-list); type final-varnameN = value; } Variables can be declared inside of interface declarations. They are implicitly final and static. They must also be initialized with a constant value. All methods and variables are implicitly public if the interface, itself, is declared as public. Here is an example of an interface definition. interface MyInterface{ void callback(int param); }