Bird
0
0

What will be the output of this code snippet?

medium📝 Predict Output Q5 of 15
Python - Encapsulation and Data Protection

What will be the output of this code snippet?

class Rectangle:
    def __init__(self, width, height):
        self._width = width
        self._height = height

    @property
    def area(self):
        return self._width * self._height

r = Rectangle(3, 4)
print(r.area)
AError: area is not callable
B7
CNone
D12
Step-by-Step Solution
Solution:
  1. Step 1: Calculate area property value

    The area property returns self._width * self._height, which is 3 * 4 = 12.
  2. Step 2: Understand property access

    Since area is a property, r.area returns 12 without parentheses.
  3. Final Answer:

    12 -> Option D
  4. Quick Check:

    Property returns calculated value without () [OK]
Quick Trick: Property returns computed value accessed like attribute [OK]
Common Mistakes:
  • Trying to call property with parentheses
  • Confusing area with sum instead of product
  • Expecting error due to missing setter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes