Question
What will be the output of the following code
snippet? class Animal: def sound(self): return "Some sound" class Dog(Animal): def sound(self): return "Bark" dog = Dog() print(dog.sound())Solution
This code demonstrates inheritance in object-oriented programming. The Dog class inherits from the Animal class. The Animal class has a method sound that returns "Some sound", while the Dog class overrides this method to return "Bark". When an instance of Dog is created and dog.sound() is called, the overridden method in Dog is executed, yielding "Bark". Why Other Options Are Wrong: A) Some sound: This option is incorrect because it represents the output of the sound method from the Animal class, which is overridden in the Dog class. C) Dog: This option is incorrect because it does not correspond to any return value from the sound method; it is not a valid method output. D) None: This option is incorrect as it implies that the sound method does not return anything, which is not true; it returns "Bark". E) Animal: This option is incorrect because it does not represent the output of any method in the code.
When two ice cubes are pressed together, they join to form one cube. Which one of the following helps to hold them together?
“Theory of Union Control of Industry” was propounded by?
A certain sum becomes Rs. 2,356 in 3 years and Rs. 2,660 in 5 years on simple interest. The value of the sum is:
The difference between a discount of 40% and two successive discounts of 30% on a certain bill was ₹220. Find the amount of the bill (in ₹).
An observatory ‘Vedh Shala’ or Jantar Mantar was built in the 18th century by which ruler of Ujjain?
An example of intangible asset is:
A rectangle has an area 30 cm 2 and perimeter 26 cm. its length (in cm) is
Which leader is called the 'father' of India's social reform movement?
In order to save the stored food grains from insects, farmers usually mix with them
Integrated Child Development Services is one of the world’s largest and unique early childhood care and development programmes of the GoI, launched in...