Course contents:
- Content
- Defining a package
- Access protection
- Importing packages
- Defining interfaces
- Applying
interfaces
An interface is similar to a class that
can contain only constants, group of related method signatures, and nested
types. There is no method body that is we cannot define methods inside the interface.
Interfaces cannot be instantiated they can only
be implemented by classes or extended by other interfaces. Those classes
that implement the interface must define the methods that are declared inside the
interface. An interface is defined much like class.
The general syntax of interface definition is
Access specifier interface interfacename
{
return
type method-name1(parameter-list);
return
type method-name1(parameter-list);
return
type method-name1(parameter-list);
return
type method-name1(parameter-list);
type variable-name1
= value;
type variable-name2
= value;
……………..
…………….
return
type methodnameN(parameter-list);
type variable-nameN
= value;
}
Here, access specifier is optional. When an access
sepecifier is not specified then interface is only available to members of the package
in which it is declared. When it is declared as public, the interface can be used
by any other code.