Python Programming - Tricky Questions - Discussion

Discussion Forum : Tricky Questions - General Questions (Q.No. 26)
26.
Consider the following Python code:
class CustomClass:
    def __init__(self, value):
        self.__value = value

    def get_value(self):
        return self.__value

obj = CustomClass(42)
result = obj.get_value()
print(result)
What will be the value of result?
42
This code will result in an error.
0
None
Answer: Option
Explanation:
The private attribute __value is accessed through the public method get_value.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.