Online Software Educational Training - IT Tutorials - Online Education Training for Computer Software


Home

JAVA PROGRAMMING

Defining an Interface

Defining an Interface 

The following figure shows that an interface definition has two components: the interface declaration and the interface body. The interface declaration declares various attributes about the interface such as its name and whether it extends another interface. The interface body contains the constant and method declarations within that interface. 

The Interface Declaration

The declaration for the Sleeper interface uses the two required elements of an interface declaration--the interface keyword and the name of the interface--plus the public access modifier : 

public interface interface-name {
. . .
}

An interface declaration can have one other component: the public access specifier and a list of superinterfaces. 

The public access specifier indicates that the interface can be used by any class in any package. If you do not specify that your interface is public, then your interface will be accessible only to classes that are defined in the same package as the interface. 


Previous

Next