Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 85)
85.
Consider the following Python code:
class Temperature:
    def __init__(self, __celsius):
        self.__celsius = __celsius

    def to_fahrenheit(self):
        return (self.__celsius * 9/5) + 32
What is the purpose of the to_fahrenheit() method?
To retrieve the temperature in Fahrenheit
To set a new temperature in Fahrenheit
To convert the temperature to Fahrenheit
To expose all internal details of the class
Answer: Option
Explanation:
The to_fahrenheit() method converts the temperature from Celsius to Fahrenheit, demonstrating encapsulation.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.