Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 97)
97.
Consider the following Python code:
class Triangle:
    def __init__(self, __base, __height):
        self.__base = __base
        self.__height = __height

    def calculate_area(self):
        return 0.5 * self.__base * self.__height
What is the purpose of the calculate_area() method?
To retrieve the area of the triangle
To set a new area for the triangle
To calculate the area of the triangle
To expose all internal details of the class
Answer: Option
Explanation:
The calculate_area() method calculates and returns the area of the triangle, demonstrating encapsulation.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.