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.
- Simplify the expression:
30% of [140% of (50 + 30) + 110] ÷ 70 × 100 24% of 15% of 500 + 122 = ?2 – (232 ÷ 2)
If (3 × 144 – 252 ÷ 14) ÷ 18 = √1024 – x, then find the value of ‘x’.
- What will come in place of (?), in the given expression.
144 ÷ √36 + 13² – 100 = ? {(80% of 650 + 25 × 12) – 20 × ?} = 760
31% of 1900 - ? = 73
Simplify the following expression.
(3-3 × 3 + 3 ÷ 3 + 3 × 5) × 2 of 5 + (2 + 2 ÷ 2 + 2 × 2 - 2)
Find the value of ‘x’ if (5 × 196 – 340 ÷ 17) ÷ 20 = √1600 – x.
The value of 42 ÷ 9 of 6 - [64 ÷  48 x 3 – 15 ÷ 8 x (11 – 17) ÷ 9] ÷ 14 is:
√529 + √64 + 92 = ?