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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
What is abstraction?1m 47s
-
(Locked)
Using abstract classes in Java to reduce code complexity5m 59s
-
(Locked)
Using interfaces in Java to provide conformity5m 1s
-
(Locked)
Discovering abstraction in Java source code4m 55s
-
(Locked)
Challenge: Leverage abstraction to write simpler applications1m 19s
-
(Locked)
Solution: Leverage abstraction to write simpler applications2m 58s
-
(Locked)
-