Call Frames Final Review Spring 2018 CS 1110

Slides:



Advertisements
Similar presentations
Python Objects and Classes
Advertisements

CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
A Level Computing#BristolMet Session Objectives#U2 S8 MUST identify the difference between a procedure and a function SHOULD explain the need for parameters.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
1 Review of classes and subclasses M fast through this material, since by now all have seen it in CS100 or the Java bootcamp First packages Then classes.
CS 1110 Prelim I: Review Session. Exam Info Prelim 1: 7:30–9:00PM, Thursday, 6 October, Statler Auditorium Look at the previous Prelims Arrive early!
Chapter 2 Writing Simple Programs
Vocabulary Key Terms polymorphism - Selecting a method among many methods that have the same name. subclass - A class that inherits variables and methods.
Python: Classes By Matt Wufsus. Scopes and Namespaces A namespace is a mapping from names to objects. ◦Examples: the set of built-in names, such as the.
CPTR 124 Review for Test 1. Development Tools Editor Similar to a word processor Allows programmer to compose/save/edit source code Compiler/interpreter.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Functions and subroutines – Computer and Programming.
Introduction. 2COMPSCI Computer Science Fundamentals.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
P YTHON ’ S C LASSES Ian Wynyard. I NTRODUCTION TO C LASSES A class is the scope in which code is executed A class contains objects and functions that.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
Constructors & Garbage Collection Ch. 9 – Head First Java.
Introduction to Computing Using Python Namespaces – Local and Global  The Purpose of Functions  Global versus Local Namespaces  The Program Stack 
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Guide to Programming with Python Chapter Eight (Part I) Object Oriented Programming; Classes, constructors, attributes, and methods.
Passing Parameters. 2 home back first prev next last What Will I Learn? List the types of parameter modes Create a procedure that passes parameters Identify.
Chapter 17 Q and A Victor Norman, et al. CS104. What is Object-oriented Programming? Q: What is object-oriented programming? A: It means defining classes/objects,
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
Chapter 9 Life & Death of an Object Stacks & Heaps; Constructors Garbage Collector (gc)
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
ITERATION. Iteration Computers are often used to automate repetitive tasks. Repeating identical or similar tasks without making errors is something that.
Review Expressions and operators Iteration – while-loop – for-loop.
PYTHON FUNCTIONS. What you should already know Example: f(x) = 2 * x f(3) = 6 f(3)  using f() 3 is the x input parameter 6 is the output of f(3)
1. Understanding the execution of local variable declaration (in a method body) new expression ( 3 steps ) method call (method frames, call stack) examples.
Introduction to java (class and object). Programming languages: –Easier to understand than CPU instructions –Needs to be translated for the CPU to understand.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
Chapter 2 Writing Simple Programs
Class Inheritance Part I
Topic: Recursion – Part 2
Topic: Functions – Part 1
7.1 What Is An Object Object-oriented program - Description or simulation of application Object-oriented programming is done by adopting or extending an.
Python Loops and Iteration
CSSE 120—Rose Hulman Institute of Technology
CS 1110 Introduction to Programming Spring 2017
CS-104 Final Exam Review Victor Norman.
Topic: Functions – Part 2
CS Week 14 Jim Williams, PhD.
Using local variable without initialization is an error.
Procedural Abstraction Object-Oriented Code
CS/ENGRD 2110 Spring 2018 Lecture 2: Objects and classes in Java
Stack Lesson xx   This module shows you the basic elements of a type of linked list called a stack.
CS 302 Week 11 Jim Williams, PhD.
Python Classes By Craig Pennell.
CS 1110 Final Exam: Review Session 1 Drawing frames for calls, executing method calls Biggest issue!!! You can’t do questions on this topic correctly.
Sit next to someone. Today, we do some work in pairs.
Variables Table counter = 1 while counter < 4: print("Happy days") counter = counter + 1 print(“End of program”) What is printed?
Sit next to someone. Today, we do some work in pairs.
CS 1110 Final Exam: Review Session 1 Drawing frames for calls, executing method calls Biggest issue!!! You can’t do questions on this topic correctly.
CS/ENGRD 2110 Spring 2019 Lecture 2: Objects and classes in Java
Namespaces – Local and Global
Review Session Biggest discrepancy questions
6.001 SICP Environment model
Review for Final Exam.
Functions Jay Summet.
CS 1111 Introduction to Programming Spring 2019
Introduction to Computer Science
CS 1110 Prelim I: Review Session Spring 2011
CS/ENGRD 2110 Spring 2019 Lecture 2: Objects and classes in Java
CSE 190p University of Washington Michael Ernst
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
Review 4 Lists and Sequences.
Namespaces – Local and Global
Functions Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Functions Jay Summet.
Lecture 2 - Names & Functions
Presentation transcript:

Call Frames Final Review Spring 2018 CS 1110

The Big Issue Cannot answer questions on this topic without drawing variables drawing frames for function calls drawing objects when they are created Learning to do this is useful in general Helps you “think like a computer” Easier to find errors in your programs.

What Do You Need to Know? Major topics Examples from previous exams local variables (in a function body) function call (call frames, call stack) class folders, inheritance, and constructor calls Examples from previous exams Question 3 on prelim 1 Question 6 on prelim 2

Important Code execution is an important part of the final You need to know how to draw variables draw call frames draw objects The purpose of such questions on executing statements with constructs and function calls is to test your understanding of how Python programs are executed.

The Frame (box) for a Function Call Function Frame: Representation of function call A conceptual model of Python • Number of statement in the function body to execute next • Starts with function’s first executable statement Draw parameters as variables (named boxes) local variables (when assigned) parameters function name instruction counter

Iterative Example Call Stack: Global Space: countVowels 1 def countVowels(word): """Returns: The number of vowels in the string s. Precondition: s is a string""" 1 x = 0 2 count = 0 3 while x < len(word): 4 if word[x] in [‘a’,’e’,’i’,’o’,’u’]: 5 count += 1 6 x += 1 7 return count countVowels ‘hi’ word 1 Global Space: Call: e = count_vowels(‘hi’)

Iterative Example Call Stack: Global Space: countVowels 1, 2 def countVowels(word): """Returns: The number of vowels in the string s. Precondition: s is a string""" 1 x = 0 2 count = 0 3 while x < len(word): 4 if word[x] in [‘a’,’e’,’i’,’o’,’u’]: 5 count += 1 6 x += 1 7 return count countVowels ‘hi’ x word 1, 2 Global Space: Call: e = count_vowels(‘hi’)

Iterative Example Call Stack: Global Space: countVowels 1, 2, 3 def countVowels(word): """Returns: The number of vowels in the string s. Precondition: s is a string""" 1 x = 0 2 count = 0 3 while x < len(word): 4 if word[x] in [‘a’,’e’,’i’,’o’,’u’]: 5 count += 1 6 x += 1 7 return count countVowels ‘hi’ x word count 1, 2, 3 Global Space: Call: e = count_vowels(‘hi’)

Iterative Example Call Stack: Global Space: countVowels 1, 2, 3, 4 def countVowels(word): """Returns: The number of vowels in the string s. Precondition: s is a string""" 1 x = 0 2 count = 0 3 while x < len(word): 4 if word[x] in [‘a’,’e’,’i’,’o’,’u’]: 5 count += 1 6 x += 1 7 return count countVowels ‘hi’ x word count 1, 2, 3, 4 Global Space: Call: e = count_vowels(‘hi’)

Iterative Example Call Stack: Global Space: countVowels 1, 2, 3, 4, 6 def countVowels(word): """Returns: The number of vowels in the string s. Precondition: s is a string""" 1 x = 0 2 count = 0 3 while x < len(word): 4 if word[x] in [‘a’,’e’,’i’,’o’,’u’]: 5 count += 1 6 x += 1 7 return count countVowels ‘hi’ x word count 1, 2, 3, 4, 6 Global Space: Call: e = count_vowels(‘hi’)

Iterative Example Call Stack: Global Space: countVowels def countVowels(word): """Returns: The number of vowels in the string s. Precondition: s is a string""" 1 x = 0 2 count = 0 3 while x < len(word): 4 if word[x] in [‘a’,’e’,’i’,’o’,’u’]: 5 count += 1 6 x += 1 7 return count countVowels ‘hi’ x 0 1 word count 1, 2, 3, 4, 6, 3 Global Space: Call: e = count_vowels(‘hi’)

Iterative Example Call Stack: Global Space: countVowels def countVowels(word): """Returns: The number of vowels in the string s. Precondition: s is a string""" 1 x = 0 2 count = 0 3 while x < len(word): 4 if word[x] in [‘a’,’e’,’i’,’o’,’u’]: 5 count += 1 6 x += 1 7 return count countVowels ‘hi’ x 0 1 word count 1, 2, 3, 4, 6, 3, 4 Global Space: Call: e = count_vowels(‘hi’)

Iterative Example Call Stack: Global Space: countVowels def countVowels(word): """Returns: The number of vowels in the string s. Precondition: s is a string""" 1 x = 0 2 count = 0 3 while x < len(word): 4 if word[x] in [‘a’,’e’,’i’,’o’,’u’]: 5 count += 1 6 x += 1 7 return count countVowels ‘hi’ x 0 1 word count 1, 2, 3, 4, 6, 3, 4, 5 Global Space: Call: e = count_vowels(‘hi’)

Iterative Example Call Stack: Global Space: countVowels def countVowels(word): """Returns: The number of vowels in the string s. Precondition: s is a string""" 1 x = 0 2 count = 0 3 while x < len(word): 4 if word[x] in [‘a’,’e’,’i’,’o’,’u’]: 5 count += 1 6 x += 1 7 return count countVowels ‘hi’ x 0 1 word count 1, 2, 3, 4, 6, 3, 4, 5, 6 Global Space: Call: e = count_vowels(‘hi’)

Iterative Example Call Stack: Global Space: countVowels def countVowels(word): """Returns: The number of vowels in the string s. Precondition: s is a string""" 1 x = 0 2 count = 0 3 while x < len(word): 4 if word[x] in [‘a’,’e’,’i’,’o’,’u’]: 5 count += 1 6 x += 1 7 return count countVowels ‘hi’ x 0 1 2 word count 0 1 1, 2, 3, 4, 6, 3, 4, 5, 6, 3 Global Space: Call: e = count_vowels(‘hi’)

Iterative Example Call Stack: Global Space: countVowels def countVowels(word): """Returns: The number of vowels in the string s. Precondition: s is a string""" 1 x = 0 2 count = 0 3 while x < len(word): 4 if word[x] in [‘a’,’e’,’i’,’o’,’u’]: 5 count += 1 6 x += 1 7 return count countVowels ‘hi’ x 0 1 2 word count 0 1 1, 2, 3, 4, 6, 3, 4, 5, 6, 3, 7 Global Space: Call: e = count_vowels(‘hi’)

Iterative Example Call Stack: Global Space: countVowels def countVowels(word): """Returns: The number of vowels in the string s. Precondition: s is a string""" 1 x = 0 2 count = 0 3 while x < len(word): 4 if word[x] in [‘a’,’e’,’i’,’o’,’u’]: 5 count += 1 6 x += 1 7 return count countVowels ‘hi’ x 0 1 2 word count 0 1 1, 2, 3, 4, 6, 3, 4, 5, 6, 3, 7 1 RETURN Global Space: Call: e = count_vowels(‘hi’)

Iterative Example Call Stack: Global Space: countVowels def countVowels(word): """Returns: The number of vowels in the string s. Precondition: s is a string""" 1 x = 0 2 count = 0 3 while x < len(word): 4 if word[x] in [‘a’,’e’,’i’,’o’,’u’]: 5 count += 1 6 x += 1 7 return count countVowels ‘hi’ x 0 1 2 word count 0 1 1, 2, 3, 4, 6, 3, 4, 5, 6, 3, 7 1 RETURN Global Space: e 1 Call: e = count_vowels(‘hi’)

Subcall Example Call Stack: Global Space: Heap Space: list id1 a 1 def printWeather(wkList): for item in wkList: dayWeather(item) def dayWeather(day): if day == ‘Sunny’: print (‘Time for a picnic!’) if day == ‘Rainy’: print (‘Grab your umbrella!’) a id1 Heap Space: printWeather id1 wkList 1 list id1 1 ‘Rainy’ ‘Sunny’ 1 2 3 4 5 6 Call: printWeather(a)

Subcall Example Call Stack: Global Space: Heap Space: list id1 a 1 def printWeather(wkList): for item in wkList: dayWeather(item) def dayWeather(day): if day == ‘Sunny’: print (‘Time for a picnic!’) if day == ‘Rainy’: print (‘Grab your umbrella!’) a id1 Heap Space: printWeather id1 item ‘Rainy’ wkList 1, 2 list id1 1 ‘Rainy’ ‘Sunny’ 1 2 3 4 5 6 Call: printWeather(a)

Subcall Example Call Stack: Global Space: Heap Space: list id1 a 1 def printWeather(wkList): for item in wkList: dayWeather(item) def dayWeather(day): if day == ‘Sunny’: print (‘Time for a picnic!’) if day == ‘Rainy’: print (‘Grab your umbrella!’) a id1 Heap Space: printWeather id1 item ‘Rainy’ wkList 1, 2 list id1 1 ‘Rainy’ ‘Sunny’ 1 2 dayWeather ‘Rainy’ day 3 3 4 5 6 Call: printWeather(a)

Subcall Example Call Stack: Global Space: Heap Space: list id1 a 1 def printWeather(wkList): for item in wkList: dayWeather(item) def dayWeather(day): if day == ‘Sunny’: print (‘Time for a picnic!’) if day == ‘Rainy’: print (‘Grab your umbrella!’) a id1 Heap Space: printWeather id1 item ‘Rainy’ wkList 1, 2 list id1 1 ‘Rainy’ ‘Sunny’ 1 2 dayWeather ‘Rainy’ day 3, 5 3 4 5 6 Call: printWeather(a)

Subcall Example Call Stack: Global Space: Heap Space: list id1 a 1 def printWeather(wkList): for item in wkList: dayWeather(item) def dayWeather(day): if day == ‘Sunny’: print (‘Time for a picnic!’) if day == ‘Rainy’: print (‘Grab your umbrella!’) a id1 Heap Space: printWeather id1 item ‘Rainy’ wkList 1, 2 list id1 1 ‘Rainy’ ‘Sunny’ 1 2 dayWeather ‘Rainy’ day 3, 5, 6 3 4 5 6 Call: printWeather(a)

Subcall Example Call Stack: Global Space: Heap Space: list id1 a 1 def printWeather(wkList): for item in wkList: dayWeather(item) def dayWeather(day): if day == ‘Sunny’: print (‘Time for a picnic!’) if day == ‘Rainy’: print (‘Grab your umbrella!’) a id1 Heap Space: printWeather id1 item ‘Rainy’ wkList 1, 2 list id1 1 ‘Rainy’ ‘Sunny’ 1 2 dayWeather ‘Rainy’ day 3, 5, 6 3 4 5 6 None RETURN Call: printWeather(a) Output: Grab your umbrella!

Subcall Example Call Stack: Global Space: Heap Space: list id1 a 1 def printWeather(wkList): for item in wkList: dayWeather(item) def dayWeather(day): if day == ‘Sunny’: print (‘Time for a picnic!’) if day == ‘Rainy’: print (‘Grab your umbrella!’) a id1 Heap Space: printWeather id1 item ‘Rainy’ wkList 1, 2, 1 list id1 1 ‘Rainy’ ‘Sunny’ 1 2 dayWeather ‘Rainy’ day 3, 5, 6 3 4 5 6 None RETURN Call: printWeather(a) Output: Grab your umbrella!

Subcall Example Call Stack: Global Space: Heap Space: list id1 a 1 def printWeather(wkList): for item in wkList: dayWeather(item) def dayWeather(day): if day == ‘Sunny’: print (‘Time for a picnic!’) if day == ‘Rainy’: print (‘Grab your umbrella!’) a id1 Heap Space: printWeather id1 item ‘Rainy’, ‘Sunny’ wkList 1, 2, 1, 2 list id1 1 ‘Rainy’ ‘Sunny’ 1 2 dayWeather ‘Rainy’ day 3, 5, 6 3 4 5 6 None RETURN Call: printWeather(a) Output: Grab your umbrella!

Subcall Example Call Stack: Global Space: Heap Space: list id1 a 1 def printWeather(wkList): for item in wkList: dayWeather(item) def dayWeather(day): if day == ‘Sunny’: print (‘Time for a picnic!’) if day == ‘Rainy’: print (‘Grab your umbrella!’) a id1 Heap Space: printWeather id1 item ‘Rainy’, ‘Sunny’ wkList 1, 2, 1, 2 list id1 1 ‘Rainy’ ‘Sunny’ 1 2 dayWeather ‘Rainy’ day 3, 5, 6 3 4 5 6 None RETURN dayWeather ‘Sunny’ day 3 Call: printWeather(a) Output: Grab your umbrella!

Subcall Example Call Stack: Global Space: Heap Space: list id1 a 1 def printWeather(wkList): for item in wkList: dayWeather(item) def dayWeather(day): if day == ‘Sunny’: print (‘Time for a picnic!’) if day == ‘Rainy’: print (‘Grab your umbrella!’) a id1 Heap Space: printWeather id1 item ‘Rainy’, ‘Sunny’ wkList 1, 2, 1, 2 list id1 1 ‘Rainy’ ‘Sunny’ 1 2 dayWeather ‘Rainy’ day 3, 5, 6 3 4 5 6 None RETURN dayWeather ‘Sunny’ day 3, 4 Call: printWeather(a) Output: Grab your umbrella!

Subcall Example Call Stack: Global Space: Heap Space: list id1 a 1 def printWeather(wkList): for item in wkList: dayWeather(item) def dayWeather(day): if day == ‘Sunny’: print (‘Time for a picnic!’) if day == ‘Rainy’: print (‘Grab your umbrella!’) a id1 Heap Space: printWeather id1 item ‘Rainy’, ‘Sunny’ wkList 1, 2, 1, 2 list id1 1 ‘Rainy’ ‘Sunny’ 1 2 dayWeather ‘Rainy’ day 3, 5, 6 3 4 5 6 None RETURN dayWeather ‘Sunny’ day 3, 4, 5 Call: printWeather(a) Output: Grab your umbrella!

Subcall Example Call Stack: Global Space: Heap Space: list id1 a 1 def printWeather(wkList): for item in wkList: dayWeather(item) def dayWeather(day): if day == ‘Sunny’: print (‘Time for a picnic!’) if day == ‘Rainy’: print (‘Grab your umbrella!’) a id1 Heap Space: printWeather id1 item ‘Rainy’, ‘Sunny’ wkList 1, 2, 1, 2 list id1 1 ‘Rainy’ ‘Sunny’ 1 2 dayWeather ‘Rainy’ day 3, 5, 6 3 4 5 6 None RETURN dayWeather ‘Sunny’ day 3, 4, 5 Call: printWeather(a) None RETURN Output: Grab your umbrella! Time for a picnic!

Subcall Example Call Stack: Global Space: Heap Space: list id1 a 1 def printWeather(wkList): for item in wkList: dayWeather(item) def dayWeather(day): if day == ‘Sunny’: print (‘Time for a picnic!’) if day == ‘Rainy’: print (‘Grab your umbrella!’) a id1 Heap Space: printWeather id1 item ‘Rainy’, ‘Sunny’ wkList 1, 2, 1, 2 list id1 1 ‘Rainy’ ‘Sunny’ 1 2 dayWeather ‘Rainy’ day 3, 5, 6 3 4 5 6 None RETURN dayWeather ‘Sunny’ day 3, 4, 5 Call: printWeather(a) None RETURN Output: Grab your umbrella! Time for a picnic!

Subcall Example Call Stack: Global Space: Heap Space: list id1 a 1 def printWeather(wkList): for item in wkList: dayWeather(item) def dayWeather(day): if day == ‘Sunny’: print (‘Time for a picnic!’) if day == ‘Rainy’: print (‘Grab your umbrella!’) a id1 Heap Space: printWeather id1 item ‘Rainy’, ‘Sunny’ wkList 1, 2, 1, 2 list id1 1 ‘Rainy’ ‘Sunny’ None RETURN 1 2 dayWeather ‘Rainy’ day 3, 5, 6 3 4 5 6 None RETURN dayWeather ‘Sunny’ day 3, 4, 5 Call: printWeather(a) None RETURN Output: Grab your umbrella! Time for a picnic!

Subcall Example Call Stack: Global Space: Heap Space: list id1 a 1 def printWeather(wkList): for item in wkList: dayWeather(item) def dayWeather(day): if day == ‘Sunny’: print (‘Time for a picnic!’) if day == ‘Rainy’: print (‘Grab your umbrella!’) a id1 Heap Space: printWeather id1 item ‘Rainy’, ‘Sunny’ wkList 1, 2, 1, 2 list id1 1 ‘Rainy’ ‘Sunny’ None RETURN 1 2 dayWeather ‘Rainy’ day 3, 5, 6 3 4 5 6 None RETURN dayWeather ‘Sunny’ day 3, 4, 5 Call: printWeather(a) None RETURN Output: Grab your umbrella! Time for a picnic!

Diagramming Objects (Folders) Object Folder Class Folder Folder Name (arbitrary) No folder name id4 classname classname Class Attributes Method Names Instance Attributes Draw attributes as named box w/ value Parameters are required in methods

Evaluation of a Constructor Call 3 steps to evaluating the call C(args) Create a new folder (object) of class C Give it with a unique name (any number will do) Folder goes into heap space Execute the method __init__(args) Yield the name of the object as the value A constructor call is an expression, not a command Does not put name in a variable unless you assign it

Diagramming Subclasses Important Details: Make sure you put the superclass-name in parentheses Do not duplicate inherited methods and attributes Include initializer and and other special methods (as applicable) Method parameters are required Class attributes are a box with (current) value superclass-name Declared in Superclass: Class Attributes Method Names subclass-name(super) Declared in Subclass: Class Attributes Method Names

Two Example Classes class A(object): x=3 y=5 def __init__(self,y): self.y = y def f(self): return self.g() def g(self): return self.x+self.y  class B(A): y=4 z=10 def __init__(self,x,y): super().__init__(y) self.x = x def g(self): return self.x+self.z def h(self): return 42

Class Folders A A __init__(self,x) f(self) g(self) __init__(self,x) f(self) g(self) These folders will still exist in the following slides, but will not be redrawn; they exist in the heap space along with the object folders. x x 3 3 y y 5 5 B(A) __init__(self,x,y) g(self) h(self) x 4 y 10

Constructor Examples Call Stack: Global Space: Heap Space: A id8 class A(object): x = 3 y = 5 def __init__(self,y): self.y = y class B(A): y = 4 z = 10 def __init__(self,x,y): super().__init__(y) self.x = x Heap Space: A.__init__ id8 self 1 A id8 y 1 1 2 3 Call: a = A(1) b = B(7, 3)

Constructor Examples Call Stack: Global Space: Heap Space: A id8 y 1 class A(object): x = 3 y = 5 def __init__(self,y): self.y = y class B(A): y = 4 z = 10 def __init__(self,x,y): super().__init__(y) self.x = x Heap Space: A.__init__ id8 self 1 ‘Rainy’ A id8 y id8 RETURN y 1 1 1 2 3 Call: a = A(1) b = B(7, 3)

Constructor Examples Call Stack: Global Space: Heap Space: A id8 a y 1 class A(object): x = 3 y = 5 def __init__(self,y): self.y = y class B(A): y = 4 z = 10 def __init__(self,x,y): super().__init__(y) self.x = x a id8 Heap Space: A.__init__ id8 self 1 ‘Rainy’ A id8 y id8 RETURN y 1 1 1 2 3 Call: a = A(1) b = B(7, 3)

Constructor Examples Call Stack: Global Space: Heap Space: A id8 B id4 class A(object): x = 3 y = 5 def __init__(self,y): self.y = y class B(A): y = 4 z = 10 def __init__(self,x,y): super().__init__(y) self.x = x a id8 Heap Space: A.__init__ id8 self 1 y ‘Rainy’ A id8 y id8 RETURN 1 B.__init__ id4 self 2 y 3 1 x 7 B id4 2 3 Call: a = A(1) b = B(7, 3)

Constructor Examples Call Stack: Global Space: Heap Space: A id8 B id4 class A(object): x = 3 y = 5 def __init__(self,y): self.y = y class B(A): y = 4 z = 10 def __init__(self,x,y): super().__init__(y) self.x = x a id8 Heap Space: A.__init__ id8 self 1 y ‘Rainy’ A id8 y id8 RETURN 1 B.__init__ id4 self 2 y 3 1 x 7 B id4 A.__init__ id4 self 1 y 3 2 3 Call: a = A(1) b = B(7, 3)

Constructor Examples Call Stack: Global Space: Heap Space: A id8 B id4 class A(object): x = 3 y = 5 def __init__(self,y): self.y = y class B(A): y = 4 z = 10 def __init__(self,x,y): super().__init__(y) self.x = x a id8 Heap Space: A.__init__ id8 self 1 y ‘Rainy’ A id8 y id8 RETURN 1 B.__init__ id4 self 2 y 3 1 x 7 B id4 A.__init__ id4 self 1 y 3 2 3 y 3 id4 RETURN Call: a = A(1) b = B(7, 3)

Constructor Examples Call Stack: Global Space: Heap Space: A id8 B id4 class A(object): x = 3 y = 5 def __init__(self,y): self.y = y class B(A): y = 4 z = 10 def __init__(self,x,y): super().__init__(y) self.x = x a id8 Heap Space: A.__init__ id8 self 1 y ‘Rainy’ A id8 y id8 RETURN 1 B.__init__ id4 self 2, 3 y 3 1 x 7 B id4 A.__init__ id4 self 1 y 3 2 3 y 3 id4 RETURN Call: a = A(1) b = B(7, 3)

Constructor Examples Call Stack: Global Space: Heap Space: A id8 B id4 class A(object): x = 3 y = 5 def __init__(self,y): self.y = y class B(A): y = 4 z = 10 def __init__(self,x,y): super().__init__(y) self.x = x a id8 Heap Space: A.__init__ id8 self 1 y ‘Rainy’ A id8 y id8 RETURN 1 B.__init__ id4 self 2, 3 3 y 1 x 7 x 7 RETURN id4 B id4 A.__init__ id4 self 1 y 3 2 3 y 3 id4 RETURN x 7 Call: a = A(1) b = B(7, 3)

Constructor Examples Call Stack: Global Space: Heap Space: A id8 B id4 class A(object): x = 3 y = 5 def __init__(self,y): self.y = y class B(A): y = 4 z = 10 def __init__(self,x,y): super().__init__(y) self.x = x a id8 Heap Space: A.__init__ id8 self 1 y b id4 ‘Rainy’ A id8 y id8 RETURN 1 B.__init__ id4 self 2, 3 3 y 1 x 7 x 7 RETURN id4 B id4 A.__init__ id4 self 1 y 3 2 3 y 3 id4 RETURN x 7 Call: a = A(1) b = B(7, 3)