Complete the code to make class Dog inherit from class Animal.
class Animal: def __init__(self, name): self.name = name class Dog([1]): pass
The class Dog inherits from Animal by putting Animal in parentheses after the class name.
Complete the code to call the parent class constructor inside the child class.
class Animal: def __init__(self, name): self.name = name class Dog(Animal): def __init__(self, name, breed): [1](name) self.breed = breed
self.__init__ which causes infinite recursion.Use super().__init__(name) to call the parent class constructor properly.
Fix the error in the code to correctly inherit and use the method from the parent class.
class Animal: def speak(self): return "Animal sound" class Cat(Animal): def speak(self): return [1]
self.speak() inside speak causes infinite recursion.super() and missing the instance.Use super().speak() to call the parent method inside the child method.
Fill both blanks to create a child class that inherits and extends the parent class method.
class Vehicle: def description(self): return "Vehicle" class Car([1]): def description(self): return super().[2]() + " - Car"
The class Car inherits from Vehicle, and calls the parent's description method using super().description().
Fill all three blanks to create a child class that inherits attributes and overrides a method using the parent method.
class Person: def __init__(self, name): self.name = name def greet(self): return f"Hello, I am {self.name}" class Student([1]): def __init__(self, name, student_id): [2](name) self.student_id = student_id def greet(self): return [3]() + f", my student ID is {self.student_id}"
self.__init__ instead of super().__init__.super() to call the parent method in greet.The Student class inherits from Person. It calls the parent constructor with super().__init__(name) and extends the greet method by calling super().greet().