Solution Review: Overriding Inherited Method

This lesson explains the solution for the "overriding methods" exercise.

Solution

Press + to interact
class Person(object):
def __init__(self, name, age):
self.name = name
self.age = age
def greet(self):
print("Hello")
class Customer(Person):
def __init__(self, name, age, no_of_purchases):
super().__init__(name, age)
self.no_of_purchases = no_of_purchases
def greet(self):
print(self.name + ",", self.age, "years old, purchased", self.no_of_purchases, "items")
# name = Josh, age = 25, no_of_purchases = 10
c = Customer("Josh", 25, 10)
c.greet()

Explanation

Since we need ...

Get hands-on with 1400+ tech skills courses.