Join Barron Stone for an in-depth discussion in this video Override inherited methods, part of Programming Foundations: Real-World Examples.
- Nowadays, not all cars run on gasoline, some are electric.…Electric cars have a radio and windows,…so they could inherit those methods from the Car class.…An electric car also has a color and manufacturer.…This is a white Nissan,…so it should inherit those data fields…from the Vehicle class as well.…Now, this is where I run into a bit of a problem.…The drive method for the Vehicle class uses gas,…but my electric car doesn't.…It uses electricity,…so that drive method doesn't make sense.…To create an Electric car subclass…that inherits from the Car and Vehicle classes,…I need to replace that gas-powered drive method…from the Vehicle class…with a specially designed, eco-friendly…electric-powered drive method.…
Here I have start_03_02_class_inheritance…open from the exercise files.…Now, I'll create a new class for electric cars called eCar,…which will inherit from the Car class.…Since eCar inherits the Car class,…it'll have the window and radio methods from it.…And, since the Car class inherits the Vehicle class,…
- Reusing functions
- Local vs. global variables
- Creating and naming custom objects
- Class inheritance
- Modules and packages
- Multidimensional lists and tuples
- Queues and stacks
- Creating and combining sets
- Storing data in dictionaries
- If/else and switch statements
- For vs. while loops
- Error handling
- Polling and event-driven programming
Skill Level Beginner
Programming Foundations: Design Patternswith Elisabeth Robson2h 19m Intermediate
3. Class Inheritance
4. Modules and Packages
5. Lists and Tuples
6. Queues and Stacks
9. Conditional Execution
11. Error Handling
12. Polling and Event-Driven Programming
- 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.