Kathryn introduces interfaces as a way to enforce certain fields and methods on a class. Interfaces define the behavior, but the implementation of the specific behavior is determined by the class.
- [Instructor] Interfaces are a way to enforce certain…fields or methods on a class.…Interfaces do not enforce exactly how these methods should…be implemented, but only that a particular class must have…these fields and methods.…For example let's say you have a dog class and a cat class.…In each of these classes you'll probably want to have a play…method where the pet plays with its owner.…To do this we can create a pet interface with the signature…of the play method and have the dog and cat class…implement this interface.…
By implementing the pet interface, these classes will be…forced to have a play method.…The implementation of this method is up to the classes…themselves, but the interface just forces them to have…the play method.…Let's see what this looks like in code.…Here we have the pet interface, it's a public interface…and we're calling it pet and inside of it we have…the signature for the method play, it's going to return…void, it's going to be called play and it has zero…parameters, next we're going to look at the dog class…
- Downloading Java 9 and choosing an IDE
- Understanding Java basics: data types, strings, arrays, and more
- Controlling flow with functions and loops
- Working with inheritance and interfaces
- Learning lambda
Skill Level Beginner
1. Getting Started
2. Java Basics
3. Control Flow
4. Beyond the Basics
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.