From the course: Java 8 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating and implementing interfaces

Creating and implementing interfaces - Java Tutorial

From the course: Java 8 Essential Training

Start my 1-month free trial

Creating and implementing interfaces

- In object-oriented programming, an interface is a contract. It defines a set of methods with particular signatures, and any class that implements that interface must implement those methods. We've already seen a couple of examples of interfaces: the list and the map. These are parts of the collections framework. In my existing code, I'm declaring an object that's an instance of the list interface. But then, I'm using the concrete implementation of that list, the array list. You can find out about these contracts by going to the documentation for the interfaces that are part of the core Java Class Library. The list interface, for example, says you must implement all of these different methods in order to be considered a list. And then it's up to each concrete implementation of the interface to write the exact code that's needed for its own functionality. I'll show you here how to create your own interface, and then how to implement it. I'm going to create an interface that defines…

Contents