Exam PCAP-31-03 All QuestionsBrowse all questions from this exam
Question 31

What is the expected behavior of the following code?

    Correct Answer: D

    The given code defines a class with a class attribute '__Var' and an instance method 'foo'. The 'foo' method increments the class attribute '__Var' by 1 and assigns its value to the instance attribute '__prop'. When 'foo' is called on two different instances of the class, the class attribute '__Var' is incremented to 2. Therefore, 'o2._Class__Var' ends up being 2 and 'o1._Class__prop' gets the value 1 when 'foo' is called on 'o1'. Adding these values (2 + 1) results in 3.

Discussion
DKAT2023Option: B

B is correct

Dave304409Option: D

D is correct