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.
A certain amount doubles itself when invested at r% p.a. simple interest for 10 years. Find the value of r.
Rs.26000 is split into two sums such that the Simple Interest on one part for 5 years at 10% equals the Simple Interest on the other part for 6 years at...
An amount of 'P' was invested at simple interest at the rate of (R - 2)% per annum. It becomes Rs. 7,200 in 4 years and Rs. 10,800 in 8 years. What is t...
A certain sum of money invested at R% p.a. simple interest amounts to Rs. 17760 after 4 years and Rs. 22080 after 7 years. If the same sum of money is i...
Naina lent Rs. 9,800 to Mohini for 4 years and Rs. 8,800 to Mitali for 6 years on simple interest at the same rate of interest and received Rs. 11,040 i...
The difference between simple and compound interest on Rs 2900 at a certain rate in 2 years is Rs 10.44, then what is the annual rate.
A man invested Rs. 20,000 at simple interest of 'x%' p.a. and received Rs. 40,000 after 2 years. If he had invested Rs. 25,000 at simple interest of 'x%...
A sum of money, invested for 6 years on 5% per annum simple interest, amounted to ₹169 on maturity. What was the sun invested?
Ankur invests Rs. 9,250 at 8% p.a. for 3 years on simple interest. The amount he gets back is Rs. '2k'. Find the product of digits of 'k'.
Rohit deposited Rs. ‘x’ in a bank at 8% compound interest per annum for 3 years, compounded annually. If he earned an interest of Rs. 2,597.12, find...