Learn how to define subclasses to inherit characteristics and behavior from a parent class. See how to override methods in a subclass and require subclasses to overload a method. Understand the differences between designated and convenience methods.
- [Instructor] I'm still working in the same…exercise file from the previous video.…Classes can inherit characteristics from a parent class,…or super class, including its properties, initializers,…de-initializer, methods and subscripts.…The inheriting class or a subclass can then…modify these characteristics to suit its needs.…For example, I'll define a base class vehicle,…and then I'll cut and paste the entire implementation of…electric vehicle into it.…
The only thing I need to change is…the type name where I access the type property.…Although I might also want to make the start method…an empty implementation.…I'll copy this first because I'm going to…paste it elsewhere in a moment.…To make electric vehicle now inherit…all of this from vehicle,…write a colon after the type name…followed by the super class name.…Multiple inheritance is not supported in Swift,…so classes can only inherit from a single super class.…
However, classes can adopt multiple protocols,…which I'll show you in the next video.…What if I wanted the four subclasses to implement a method,…
Learn how to write code, understand Swift's key concepts and best practices, and strengthen your programming problem-solving skills. Instructor Scott Gardner teaches the fundamentals, so you'll be prepared to develop applications for iOS, macOS, and other platforms. Completing this course will enable you to not only write first-class code, but to think like a Swift developer.
- Creating playgrounds
- Defining variables and constants
- Working with characters and strings
- Working with collections and groups
- Using operators and defining custom operators
- Controlling program flow
- Defining functions and closures
- Working with classes, structures, and enumerations
- Adopting protocols
Skill Level Beginner
1. Get Started
2. Variables and Constants
3. Characters and Strings
4. Collections and Tuples
6. Control Flow
- 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.