- Interface can be declared as abstract but it is superfluous and seldom done.
- Since interfaces are meant to be implemented by classes, interface members implicitly have public accessibility and the public modifier is omitted.
- The methods in an interface are all implicitly abstract and public. A method prototype has the same syntax as an abstract method. However, only the modifiers abstract and public are allowed, but these are normally omitted.
- A class can neither narrow the accessibility of an interface method nor specify new exceptions in method’s throws clause; as attempting to do so would amount to altering the interfaces contract, which is illegal. The criteria for overriding methods also apply when implementing interface methods.
- Interface methods cannot be declared as static. They are always implemented as instance methods.
- Regardless of how many interfaces a class implements directly or indirectly, it only provides a single implementation of a method that might have multiple declarations in the interfaces.
- Method prototype declarations can also be overloaded as in the case of classes.
- An interface can also define named constants. Such constants are defined by field declarations and are considered to be public, static and final. These modifiers are usually omitted from the declaration. Such a constant must be initialized with an initializer expression.
- An interface constant can be accessed by any client (a class or interface) using its fully qualified name, regardless of whether the client extends or implements its interface.
However, if a client is a class that implements this interface or an interface that extends this interface, then the client can also access such constants directly without using the fully qualified name. Such a client inherits the interface constants. - In the case of multiple inheritance of interface constants, any name conflicts can be resolved using fully qualified names for the constants involved.
Java, Python, Spring MVC, SpringBoot, SQL, MySQL, MariaDB, PostgreSQL and Back-end theory and code examples.
Showing posts with label Java Interface Characteristics. Show all posts
Showing posts with label Java Interface Characteristics. Show all posts
Thursday, 4 June 2015
Java Interface Characteristics
Subscribe to:
Posts (Atom)