Get startedGet started for free

Multiple inheritance

In this exercise, you'll practice implementing multiple inheritance by creating a new class, called Smartphone.

Below are the definitions for the Computer and Telephone class, which will be used when creating the Smartphone class. Make sure to take a close look at both of these classes!

class Computer:
  def __init__(self, brand):
    self.brand = brand

  def browse_internet(self):
    print(f"Using {self.brand}'s default internet browser.")
class Telephone:
  def __init__(self, phone_number):
    self.phone_number = phone_number

  def make_call(self, recipient):
    print(f"Calling {recipient} from {self.phone_number}")

This exercise is part of the course

Intermediate Object-Oriented Programming in Python

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Define a Smartphone class that inherits from Computer and
# Telephone, and takes parameters brand, phone_number, and 
# music_app
class ____(____, ____):
  def __init__(self, ____, ____, ____):
    # Call the contructor for the Computer and Telephone
    # class, define the music_app instance-level attribute
    ____.__init__(self, brand)
    Telephone.__init__(self, ____)
    self.music_app = ____
Edit and Run Code