Multiple inheritance
この演習では、Smartphone という新しいクラスを作成して、multiple inheritance(多重継承)を実装する練習をします。
以下に、Smartphone クラスを作る際に使用する Computer クラスと Telephone クラスの定義があります。どちらのクラスもよく確認してください。
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}")
この演習はコースの一部です
Python 中級オブジェクト指向プログラミング
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# 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 = ____