Vehicles That Specialize

Easy ⏱ 8 min 72% acceptance ★★★★★ 4.6
Create a base class Vehicle with __init__(self, name) and wheels() returning 4. Subclass Bike(Vehicle) overriding wheels() to return 2, inheriting the constructor untouched. Then Bike('BMX').wheels() must be 2 while Vehicle('Car').wheels() stays 4.

Examples

Example 1
Input
Bike('BMX').wheels()
Output
2
Explanation

The override shadows the base implementation.

Constraints

  • Bike must not redefine __init__.
  • Only wheels() is overridden.

Topics

OOPinheritance

Companies

UberOlaTesla

Hints

Hint 1

class Bike(Vehicle): inherits everything by default.

Hint 2

Just redefine the one method.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.