class A(object): x=3 y=5 def __init__(self,y): 1. self.y = y def f(self): 1. ret
ID: 3759561 • Letter: C
Question
class A(object): x=3 y=5 def __init__(self,y): 1. self.y = y def f(self): 1. return self.y+self.y def g(self): 1. return self.x+self.y
Draw the execution of the statement p = A(1). This is a constructor call, so it will involve the creation of a call frame for __init__. As usual, you will need a diagram for when the frame for __init__ created, and another when it is erased. In between, you will diagram the lone line of code that is executed.
However, as described above, you do not draw the call frame right away. You need a step creating the folder first. In particular, you will need to draw how global space and heap space changes with the call frame, just like you did on the prelim. You do not need to add anything to global space beyond what is required for the statement p = A(1). In particular, you do not need a global variable for class A.
Explanation / Answer
class A(object):
x=3 y=5 def __init__(self,y): 1.
self.y = y def f(self):
1. return self.y+self.y def g(self):
1. return self.x+self.y
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.