Multiple inheritance
इस अभ्यास में, आप Smartphone नाम की एक नई class बनाकर multiple inheritance को लागू करने का अभ्यास करेंगे.
नीचे Computer और Telephone class की परिभाषाएँ दी गई हैं, जिनका इस्तेमाल Smartphone class बनाते समय होगा. इन दोनों 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}")
यह अभ्यास पाठ्यक्रम का हिस्सा है
Intermediate Object-Oriented Programming in 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 = ____