215 Variable scope in OOP
In procedural programming, what are the two main types of variable scope?
What is object scope in OOP, and what type of variable has object scope?
In a method, how can you tell the difference between a local variable and an instance variable?
Compare what happens to local and instance variables after a method exits.
Given this code, what will
obj.count
print after both increment calls?
class MyClass():
def init(self):
self.count = 0
def increment(self):
self.count = self.count + 1
obj = MyClass()
obj.increment()
obj.increment()
print(obj.count)
Write a class called
Counter
that starts with a count of 10 and has a methodaddFive()
that adds 5 to the count.
Why can two different
LightSwitch
objects have different values forswitchIsOn
at the same time?
Last updated
Was this helpful?