In this video, Doug Winnie explains how use polymorphism using interfaces. Using an interface, you can define the members that are required to implement the interface, you can then type objects to the interface.
- [Narrator] There are a number of ways…we can type our objects.…One way is to type them exactly to the class they are…based on, which is how we've been doing them so far.…There are two others ways you can type your objects.…The first is to type them to a class that they extend.…In our project, we have a cat class…and a lynx class that extends the cat class.…Because lynx extends cat, we can type an object to cat,…but assign a lynx instance to it.…Here's an example. I create a cat called stray,…I can then create a new instance of lynx,…and then assign that to stray.…
We can do this because the lynx class…has everything that a cat class has.…This doesn't work the other way around, though.…That is because the lynx class has an extra method,…the growl method, that the cat doesn't have.…So that isn't possible.…There is one other way to type your projects,…and that is with an interface.…An interface is a definition that declares class members…that must be present for the…interface to be fully implemented.…It's kind of like a category.…
- The history of Java
- Setting up your development environment
- Working with values and variables
- Using methods and functions
- Capturing user input
- Creating conditional tests
- Using loops
- Creating and changing arrays
- Object-oriented programming in Java
- Defining permissions
- Extending classes
Skill Level Beginner
Computer Science Principles: The Internetwith Doug Winnie59m 30s Beginner
Java Essential Training for Studentswith Peggy Fisher3h 6m Intermediate
1. Intro to Java
2. Define Actions Using Code
3. Repeat Actions and Test for Conditions
4. Object-Oriented Programming Basics
Next steps1m 44s
- 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.