Java – Defining interfaces

Home/Java - Tutorial/Java - Interfaces/Java – Defining interfaces
Java – Defining interfaces 2017-06-13T00:23:35+00:00

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 :

 

Prev Next