From the course: Java 8+ Essential Training: Objects and APIs

Unlock the full course today

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

Create and implement interfaces

Create and implement interfaces - Java Tutorial

From the course: Java 8+ Essential Training: Objects and APIs

Start my 1-month free trial

Create and implement interfaces

- [Instructor] In object oriented programming terminology, and interface is a contract. It defines a set of methods with particular signatures. Any class that implements that interface, must implement those methods. It's a guarantee that those methods and other members of the class will be present. You can then treat that object as an instance of the interface, passing it to methods that expect objects that satisfy the contract. In this application, I'll start by creating a new interface. We already know that a shirt is one kind of clothing item. Well now, we'll extend the hierarchy by saying that clothing item is one kind of product and I'll represent product with an interface. I'll right click on the model package and choose new Java class, I'll set the name as product, but now instead of setting the kind as class, I'll set it as interface. Next, I'll list the methods that all classes that implement this method must have. I'll go to the clothing item class and I'll go get the type…

Contents