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

PCAP-31-03 Exam - Question 53


What is the expected behavior of the following code?

Show Answer
Correct Answer: A

The code demonstrates the use of a class attribute 'Var' and instance attributes 'var'. Upon creating each instance of the class (object_1 and object_2), the class attribute 'Var' is incremented by 1. Initially, 'Var' is 0. After creating object_1, 'Var' becomes 1. After creating object_2, 'Var' becomes 2. The instance attributes 'var' for object_1 and object_2 are set to 1 and 2 respectively. The print statement sums Class.Var (which is 2), object_1.var (which is 1), and object_2.var (which is 2). Hence, it outputs 2 + 1 + 2 = 5.

Discussion

1 comment
Sign in to comment
DKAT2023Option: D
Jul 12, 2024

Class didn't take argument