Question
Consider the following Python code: class
Shape:   def area(self):     return 0 class Circle(Shape):   def __ init __ (self, radius):     self.radius = radius   def area(self):     return 3.14 * self.radius * self.radius s = Shape() c = Circle(5) print(s.area()) print(c.area()) What is the output of this code?Solution
This code demonstrates polymorphism in Python. 1. Base Class Behavior: The Shape class has an area method returning 0 by default, which is inherited but overridden by the Circle class. 2. Derived Class Behavior: The Circle class redefines the area method to calculate the area of a circle using the formula πr² . 3. Output: o The first call (s.area()) invokes the area method in Shape, returning 0. o The second call (c.area()) invokes the overridden area method in Circle, calculating and returning 78.5. This demonstrates inheritance and method overriding. Why Other Options Are Incorrect: • B) 0 followed by 0: The second call correctly calculates the circle's area. • C) 78.5 followed by 78.5: The first call uses the Shape class's method, which returns 0. • D) None followed by 78.5: The area method in Shape returns 0, not None. • E) Throws an error due to missing area method in Shape: The Shape class defines the area method.
Statement: Militants are now attacking the police in several states of India in a bid to demoralize them and to choke the intelligence network.
...
The increasing amount of NPA in public sector banks is causing trouble for RBI and India’s GDP as well.
Which of the following course of action...
Statement:Â Although the tribal women are familiar with beekeeping, their conventional method does not guarantee adequate returns.
Courses of ...
A statement is given followed by two courses of action I and II. Analyse the given situation and select the appropriate course of action.
Stateme...
Statement : A vulnerability in Wi-Fi encryption has sent the entire tech industry scrambling; the so-called Krack attack affects nearly every wirele...
Statement: Malnutrition isn’t just about acute starvation and often, healthy-looking people are malnourished too, because their diet does not include...
Statement:Â Â Although the tribal women are familiar with beekeeping, their conventional method does not guarantee adequate returns.
Course...
The major road connecting the two main parts of the city is inundated due to heavy rains during past two days.
Courses of Action: (I)The govt. sh...
Statement:
According to a recent survey made by the centre for strategic and international studies (CSIS), the tiny North-eastern state Sikkim ha...
Statement: As per data provided by the education department, as many as 8,604 posts of Hindi teachers in primary schools and 1,500 in high schools are ...