Python Programming - Classes - Discussion

Discussion Forum : Classes - General Questions (Q.No. 31)
31.
Consider the following Python code:
class Animal:
    def __init__(self, species):
        self.species = species

class Dog(Animal):
    def __init__(self, species, breed):
        super().__init__(species)
        self.breed = breed

# Create an instance of the Dog class
my_dog = Dog("Canine", "Labrador")

# Access and print attributes
print(my_dog.species)
print(my_dog.breed)
What will be the output of the code?
Canine \n Labrador
Labrador \n Canine
Canine
Labrador
Answer: Option
Explanation:
The code creates an instance of the `Dog` class, initializes its attributes, and then prints the values of the `species` and `breed` attributes.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.