Home > Java > Interfaces > Definitions
Definitions

Top 10 Interfaces Definitions

1

An interface in the Java programming language is an abstract type that is used to specify an interface (in the generic sense of the term) that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signatures and constant declarations (variable declarations that are declared to be both static and final). An interface may never contain method definitions.

As interfaces are implicitly abstract, they cannot be directly instantiated except when instantiated by a class that implements the said interface. The class must implement all of the methods described in the interface, or be an abstract class. Object references in Java may be specified to be of an interface type; in which case, they must either be null, or be bound to an object that implements the interface.

One benefit of using interfaces is that they simulate multiple inheritance. All classes in Java (other than java.lang.Object, the root class of the Java type system) must have exactly one base class; multiple inheritance of classes is not allowed. Furthermore, a Java class may implement, and an interface may extend, any number of interfaces; however an interface may not implement an interface.

Author:
Wikipedia
Source:
Type:
Website

Rating: 0.0/5 (0 votes cast)

Favorite
2

An interface is a list of methods that must be defined by any class which implements that interface. It may also define constants (public static final).

Similar to abstract class. An interface is similar to a class without instance and static variables (static final constants are allowed), and without method bodies. This is essentially what a completely abstract class does, but abstract classes do allow static method definitions, and interfaces don't.

Contractual obligation. When a class specifies that it implements an interface, it must define all methods of that interface. A class can implement many different interfaces. If a class doesn't define all methods of the interfaces it agreed to define (by the implements clause), the compiler gives an error message, which typically says something like "This class must be declared abstract". An abstract class is one that doesn't implement all methods it said it would. The solution to this is almost always to implement the missing methods of the interface. A misspelled method name or incorrect parameter list is the usual cause, not that it should have been abstract!

Author:
leepoint.net
Source:
Type:
Website

Rating: 0.0/5 (0 votes cast)

Favorite
3

The interface keyword takes the abstract concept one step further. You could think of it as a “pure” abstract class. It allows the creator to establish the form for a class: method names, argument lists, and return types, but no method bodies. An interface can also contain fields, but these are implicitly static and final. An interface provides only a form, but no implementation.

An interface says: “This is what all classes that implement this particular interface will look like.” Thus, any code that uses a particular interface knows what methods might be called for that interface, and that’s all. So the interface is used to establish a “protocol” between classes. (Some object-oriented programming languages have a keyword called protocol to do the same thing.)

Author:
Bruce Eckel
Source:
Type:
Book

Rating: 0.0/5 (0 votes cast)

Favorite
4

Interfaces define and standardize the ways in which things such as people and systems can interact with one another. For example, the controls on a radio serve as an interface between radio users and a radio’s internal components. The controls allow users to perform only a limited set of operations (e.g., changing the station, adjusting the volume, choosing between AM and FM), and different radios may implement the controls in different ways (e.g., using push buttons, dials, voice commands). The interface specifies what operations a radio must permit users to perform but does not specify how the operations are performed. Similarly, the interface between a driver and a car with a manual transmission includes the steering wheel, the gear shift, the clutch pedal, the gas pedal and the brake pedal. This same interface is found in nearly all manual transmission cars, enabling someone who knows how to drive one particular manual transmission car to drive just about any manual transmission car. The components of each individual car may look different, but their general purpose is the same—to allow people to drive the car.

Software objects also communicate via interfaces. A Java interface describes a set of methods that can be called on an object, to tell the object to perform some task or return some piece of information, for example.

Author:
Deitel - Deitel
Source:
Type:
Book

Rating: 0.0/5 (0 votes cast)

Favorite
5

Sometimes we want a class to inherit from more than one other class. In Java this is accomplished indirectly using an “interface.” An interface is a class that contains only abstract methods and/or constants. The interface supplies a specification of methods and requires another class to implement the methods of the specification.

Author:
Barry J. Holmes and Daniel T. Joyce
Source:
Type:
Book

Rating: 0.0/5 (0 votes cast)

Favorite
6

Interfaces, like abstract classes and methods, provide templates of behavior that other classes are expected to implement. They also offer significant advantages in class and object design that complements Java’s single inheritance approach to object-oriented programming.

Author:
Rogers Cadenhead and Laura Lemay
Source:
Type:
Book

Rating: 0.0/5 (0 votes cast)

Favorite
7

Using interface, you can specify a set of methods which can be implemented by one or more classes. The interface, itself, does not actually define any implementation. Although they are similar to abstract classes,interfaces have an additional capability: A class can implement more than one interface. By contrast, a class can only inherit a single superclass (abstract or otherwise).

Using the keyword interface, you can fully abstract a class' interface from its implementation. That is, using interface, you can specify what a class must do, but not how it does it. Interfaces are syntactically similar to classes, but they lack instance variables, and their methods are declared without any body. In practice, this means that you can define interfaces which don't make assumptions about how they are implemented. Once it is defined, any number of classes can implement an interface. Also, one class can implement any number of interfaces. To implement an interface, a class must create the complete set of methods defined by the interface.

Author:
Patrick Naughton and Herbert Schildt
Source:
Type:
Book

Rating: 0.0/5 (0 votes cast)

Favorite
8

nterfaces are similar to abstract classes but all methods are abstract and all properties are static final. Interfaces can be inherited (ie. you can have a sub-interface). As with classes the extends keyword is used for inheritence.Java does not allow multiple inheritance for classes (ie. a subclass being the extension of more than one superclass). An interface is used to tie elements of several classes together. Interfaces are also used to separate design from coding as class method headers are specified but not their bodies. This allows compilation and parameter consistency testing prior to the coding phase. Interfaces are also used to set up unit testing frameworks.

Author:
home.cogeco.ca
Source:
Type:
Website

Rating: 0.0/5 (0 votes cast)

Favorite