课程: Java 8+ Essential Training: Objects and APIs
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Create and implement interfaces - Java教程
课程: Java 8+ Essential Training: Objects and APIs
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…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。