[ Team LiB ] Page 316

[ Team LiB ] 6.4 Interfaces Extending classes using single implementation inheritance creates new class types. A superclass reference can denote objects of its own type and its subclasses strictly according to the inheritance hierarchy. Because this relationship is linear, it rules out multiple implementation inheritance, that is, a subclass inheriting from more than one superclass. Instead Java provides interfaces, which not only allow new named reference types to be introduced, but also permit multiple interface inheritance. Defining Interfaces A top-level interface has the following general syntax: interface // Interface header { // Interface body } In the interface header, the name of the interface is preceded by the keyword interface. In addition, the interface header can specify the following information: . scope or accessibility modifier (see Section 4.7, p. 131) . any interfaces it extends (see Section 6.4, p. 254) The interface body can contain member declarations which comprise . constant declarations (see Section 6.4, p. 255) . method prototype declarations (see Section 6.4, p. 254) . nested class and interface declarations (see Section 7.1, p. 284) An interface does not provide any implementation and is, therefore, abstract by definition. This means that it cannot be instantiated, but classes can implement it by providing implementations for its method prototypes. Declaring an interface abstract is superfluous and seldom done. The member declarations can appear in any order in the interface body. Since interfaces are meant to be implemented by classes, interface members implicitly have public accessibility and the public modifier is omitted. Interfaces with empty bodies are often used as markers to tag classes as having a certain property or behavior. Such interfaces are also called ability interfaces. Java APIs provide several examples of such marker interfaces: java.lang.Cloneable, java.io.Serializable, java.util.EventListener. Method Prototype Declarations An interface defines a contract by specifying a set of method prototypes, but no implementation. The methods in an interface are all implicitly abstract and public by virtue Page 317
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check Actions tomcat hosting services

Comments are closed.