![]() |
7. Objects & Classes16 Questions
Created by Y. Daniel Liang
- http://www.cs.armstrong.edu/liang/index.html
Free
|
__________ represents an entity in the real world that can be distinctly identified.
_______ is a template, blueprint, or contract that defines objects of the same type.
The keyword __________ is required to define a class.
________ is used to create an object.
The ________ creates an object in the memory and invokes __________.
Analyze the following code:
class A:
def __init__(self, s):
self.s = s
def print(self):
print(s)
a = A("Welcome")
a.print()
Analyze the following code:
class A:
def __init__(self, s):
self.s = s
def print(self):
print(self.s)
a = A()
a.print()
Analyze the following code:
class A:
def __init__(self, s = "Welcome"):
self.s = s
def print(self):
print(self.s)
a = A()
a.print()
Given the declaration x = Circle(), which of the following statement is most accurate.
Analyze the following code:
class A:
def __init__(self):
self.x = 1
self.__y = 1
def getY(self):
return self.__y
a = A()
print(a.x)
Analyze the following code:
class A:
def __init__(self):
self.x = 1
self.__y = 1
def getY(self):
return self.__y
a = A()
print(a.__y)
Analyze the following code:
class A:
def __init__(self):
self.x = 1
self.__y = 1
def getY(self):
return self.__y
a = A()
a.x = 45
print(a.x)
In the following code,
def A:
def __init__(self):
__a = 1
self.__b = 1
self.__c__ = 1
__d__ = 1
# Other methods omitted
Which of the following is a private data field?
Analyze the following code:
class A:
def __init__(self):
self.x = 1
self.__y = 1
def getY(self):
return self.__y
a = A()
a.__y = 45
print(a.getX())
What is the value of times displayed?
def main():
myCount = Count()
times = 0
for i in range(0, 100):
increment(myCount, times)
print("myCount.count =", myCount.count, "times =", times)
def increment(c, times):
c.count += 1
times += 1
class Count:
def __init__(self):
self.count = 0
main()