When you’re working with an inheritance hierarchy, you can treat objects as either their inherent types, or as their superclass types. A shirt is a clothing item. It does everything a clothing item does, but it might do more that’s unique to shirts. To tell your code to treat an object as a particular type, use casting syntax.
- When you're working with an inheritance…hierarchy, you can treat objects as either…their inherent types, or as their superclass…types.…A shirt is a clothing item, its superclass is…a clothing item, and so it can be both.…This is the nature of what's known as…polymorphism in object-oriented programming.…Polymorphism means something can be more than…one thing at the same time.…The object does everything the clothing item…does, but it might do more that's unique to…shirts.…
In this code, I'll go to the shirt class that I…previously created, and I'm going to add a new…instance variable, or field, it'll be a string,…and its name will be Pattern.…And I'll give it a default value of "Not Set".…Next, I'll create a getter and a setter for this…new field, and now this field is available to…the rest of the application.…I'll go back to the main class where I'm using…that class.…I already have some code that's creating an…instance of the shirt class.…
And now I can use that object, Shirt, and I…can call the setter method "Set pattern".…
- Debugging Java code
- Handling exceptions
- Creating custom classes
- Working with inheritance
- Managing data collections
- Using Java packages and libraries
- Preparing a Java application for deployment
Skill Level Intermediate
1. Exception Handling and Debugging
2. Create Custom Classes
3. Work with Inheritance
4. Manage Data Collections
5. Use Java Packages and Libraries
Work with dates and times7m 12s
6. Prepare a Java Application for Deployment
Next steps1m 12s
- 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.