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

PCAP-31-03 Exam - Question 31


What is the expected behavior of the following code?

Show Answer
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

2 comments
Sign in to comment
Dave304409Option: D
Jul 3, 2024

D is correct

DKAT2023Option: B
Jul 3, 2024

B is correct