Interfaces and Inheritance


An interface can inherit the members of another interface. Unlike classes, multiple inheritance is allowed with interfaces. Interface inheritance is indicated by the extends keyword in the interface declaration.

 [modifiers] interface interface_name         extends superinterface1, superinterface2,...] {    //  method declarations    //  constant declarations } 

One reason to use interface inheritance is to extend the declarations and definitions of an existing interface. If you simply added a method declaration to an existing interface, you would break any program that had been compiled using the older version. Creating a new interface that builds upon an existing one avoids this problem.

A class that implements an interface that inherits other interfaces must provide implementations for all of the methods defined in all interfaces in the inheritance hierarchy. For example, let's say an interface named Ionized declares a method named getField() . Let's also suppose that the Ionized interface extends the Gas interface that declares two methods, getEnthalpy() and getEntropy() . A class that implemented the Ionized interface would have to provide implementation for the getField() , getEnthalpy() , and getEntropy() methods.



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net