课程: Java Object-Oriented Programming

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

Using interfaces in Java to provide conformity

Using interfaces in Java to provide conformity - Java教程

课程: Java Object-Oriented Programming

Using interfaces in Java to provide conformity

- [Instructor] Another way we can add abstraction to our Java programs is through interfaces. An interface is a set of method signatures for to-be-implemented functionality. It's kind of like a specification for a set of behavior without the implementation. So like an abstract class, an interface cannot be instantiated. Let's take a look at an example. Here we have an event interface. Any class that wants to use the event interface must implement the getTimeStamp and process methods and return the appropriate type. To use an interface, another class implements it, using the implements keyword. Let's create a class that uses this interface. We'll call it PasswordChangeEvent. This event is created when a user changes their password. To have it use the event interface, we'll use the keyword implements. Of course, we aren't done yet. In order for this class to properly implement the event interface, it must have…

内容