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.
Kathak maestro Pandit Birju Maharaj passed away. He was an exponent of the _________ Gharana.
In which year was the Bharat Bill Payment System (BBPS) launched by NPCI?
Which company has signed a Memorandum of Understanding (MoU) with Rail Vikas Nigam Limited (RVNL) to extend financial support of up to Rs. 35,000 crore ...
President Droupadi Murmu laid the foundation stone of state-owned energy firm SJVN’s 1,000 MV ____ Solar Power Project.
Which nation did India defeat to win the 2011 ICC Cricket World Cup?
The Union Cabinet has approved the National Quantum Mission (NQM) at a total cost of ________ from 2023-24 to 2030-31, aiming to seed, nurture and sca...
The Indian Institute of Technology Madras became the first Indian Institute of Technology to set up an international campus, by launching a campus in Ta...
PM Modi launches single brand 'Bharat', which is related toÂ
Where is the world's first conservation and breeding centre for Asian king vultures being established?
Which two Indian cities were recognized as Wetland Cities in 2025?