1. Učit se
  2. /
  3. Kurzy
  4. /
  5. Intermediate Object-Oriented Programming in Python

Connected

cvičení

Vícenásobná dědičnost

V tomto cvičení si procvičíš implementaci vícenásobné dědičnosti tím, že vytvoříš novou třídu Smartphone.

Níže najdeš definice tříd Computer a Telephone, které použiješ při vytváření třídy Smartphone. Pečlivě si obě třídy prohlédni!

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}")

Pokyny 1/3

undefined XP
    1
    2
    3
  • Vytvoř třídu Smartphone, která dědí z tříd Computer a Telephone a přijímá parametry brand, phone_number a music_app.
  • Zavolej konstruktory rodičovských tříd třídy Smartphone a definuj atribut instance music_app.