From the course: Java Object-Oriented Programming

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Using interfaces in Java to provide conformity

Using interfaces in Java to provide conformity - Java Tutorial

From the course: 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…

Contents