Defining interfaces

Share This Topic -

Defining interfaces in java with syntax:

Syntax :

[Access-specifier] interface interface-name


Access-specifier return-type method-name(parameter-list);

final type var1=value;


Where, Access-specifier is either public or it is not given.

When no access specifier is used, it results into default access specifier and if interface has default access specifier then it is only available to other members of the same package.

When it is declared as public, the interface can be used by any other code of other package.

       Interface-Name: name of an interface, it can be any valid identifier.

The methods which are declared having no bodies they end with a semicolon after the parameter list. Actually they are abstract methods;

Any class that includes an interface must implement all of the methods. Variables can be declared inside interface declarations.

They are implicitly final and static, means they can not be changed by implementing it in a class.

They must also be initialized with a constant value.

EX :

interface Item


       static final int code = 100;

       static final String name = "Fan";

       void display ( );



interface Area


       static final float pi = 3.14F;

       float compute ( float x, float y );

       void show ( );