PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 137


What is the expected behavior of the following code?

Show Answer
Correct Answer: C

C

Discussion

3 comments
Sign in to comment
macxszOption: C
May 4, 2022

C. it outputs 1

stuartzOption: C
Jun 20, 2022

Answer is C. Following shows interactions of class variables vs. instance variables >>> class Class: ... Var = 0 ... def __init__(self): ... self.value = 0 ... >>> obj1 = Class() >>> Class.Var += 2 >>> obj2 = Class() >>> Class.Var += 2 >>> obj1.Var += 5 >>> obj2.value += 1 >>> print(obj2.Var, obj2.value, Class.Var, obj1.Var) 4 1 4 9

seaverickOption: C
Jan 21, 2024

#question 137 class Class: Variable = 0 def __init__(self): self.value = 0 obj1 = Class() Class.Variable += 1 obj2 = Class() obj2.value += 1 print(obj2.Variable, obj2.value, Class.Variable, obj1.Variable,obj1.value) print(obj2.Variable + obj1.value) Tested: C