Question
What will be the output of the following code snippet
demonstrating abstraction in Python? from abc import ABC, abstractmethod class Shape(ABC): @abstractmethod def area(self): pass class Circle(Shape): def __init__(self, radius): self.radius = radius def area(self): return 3.14 * self.radius * self.radius circle = Circle(5) print(circle.area())Solution
In the given code snippet, an abstract base class Shape is defined with an abstract method area. The Circle class inherits from Shape and implements the area method, which calculates the area of a circle using the formula πr2\pi r^2πr2. When the Circle instance with a radius of 5 is created, calling circle.area() computes the area as 3.14×5×5=78.53.14 \times 5 \times 5 = 78.53.14×5×5=78.5. Therefore, the output is 78.5. Why Other Options Are Wrong: A) 3.14: This option is incorrect because it only represents the value of π, not the computed area. B) 31.4: This option is incorrect as it suggests a miscalculation of the area, possibly interpreting it as π multiplied by the radius. D) 25: This option is incorrect because it reflects the square of the radius (5), not the area. E) TypeError: This option is incorrect because there is no type error; the code correctly implements abstraction and executes without issues.
Who flagged off the inaugural flight of the new airline Fly91?
The first day of the Tamil calendar on 14 April is celebrated as________.
Begum Hazrat Mahal, the wife of the Nawab of _______ led the uprising at Lucknow in May, 1857.
Sitar maestro, Pandit Ravi Shankar was awarded which of the following awards by the Government of India in 1999?
With which of the following countries is the ‘Navanna’ festival associated?
Which two countries are claiming for uninhabited “Senkaku Islands”?
The National Research Foundation (NRF) Act will establish NRF, an apex body to provide high-level strategic direction of scientific research in the coun...
A rectangular lawn 60 m X 40 m has two roads each 5 m wide running in the middle of it, one parallel to length and the other parallel to breadth. The co...
The famous monument ‘Taj Mahal’ of Agra is situated on the banks of which of these rivers?
What is the target of India's Logistics Policy?