Create a Vehicle Subclass
Beginner · Write the code · from Python Inheritance: Subclasses, Polymorphism, and super()
From the lesson: Python Inheritance: Subclasses, Polymorphism, and super()
Think about how scientists classify animals. A Dog is a type of Mammal, which is a type of Animal. Each level inherits traits from the one above it: all animals breathe, all mammals are warm-blooded, and all dogs bark.
Read the lessonGiven the Vehicle class below, create a Car subclass that:
doors attribute (set in __init__)__init__ using super()Create a Car with make 'Toyota', year 2023, and 4 doors. Print its make, year, and doors on separate lines.
class Vehicle:
def __init__(self, make, year):
self.make = make
self.year = yearclass Vehicle:
def __init__(self, make, year):
self.make = make
self.year = year
# Create your Car subclass here
More Inheritance exercises
- Override the describe() MethodBeginner
- Predict the super() OutputIntermediate
- Fix the Inheritance BugIntermediate
- Build a Shape Area CalculatorIntermediate
- Build a Notification SystemAdvanced
All Python exercises · 50 practice problems · Object-Oriented Programming quiz