CS1400 FINAL EXAM QUESTIONS WITH VERIFIED
ANSWERS
Fill in the blanks in the correct order.
A _______ is a template or blueprint that is used to create a(n) ____________ of the
same type. - Answers - class, object
A ________________ is used to create an instance of a class. - Answers - constructor
What is the name of the method that is defined to customize an object, and is
automatically called when an instance of a class is created? - Answers - __init__
class A:
def __init__(self):
self.x = 1
self.__y = 2
def getY(self):
return self.__y
a = A()
print(a.__y)
************************What is printed? - Answers - Nothing because y is private
______________________ is way to diagram classes to give a visual representation. -
Answers - UML
What does UML stand for? - Answers - Unified Modeling Language
By convention the word ______________ is used as the first formal parameter of an
instance method. - Answers - self
Which of the following describes Procedural Programming? - Answers - data and
function are separate
- Separation of class implementation from the use of a class
- The implementation details are hidden from the user
- The user knows what the result is, but not how it happens
- A class is like a black box - Answers - Encapsulation and abstraction
What is the name of the built-in function that will return the number of characters in a
string or the number of elements in a list? - Answers - len
, What is the symbol for the Access Operator?
Correct! - Answers - .
Writing code to make it possible to use the // (integer division) symbol on an object is
called - Answers - operator overloading
What is the method that can be defined to change the meaning of the - (minus) symbol?
- Answers - __sub__
class Widget:
def __init__(self, value):
self.value = value
def getMultiple(self, multiplier):
return self.value * multiplier
What is getMultiple? - Answers - method
class Widget:
def __init__(self, value):
self.value = value
def getMultiple(self, multiplier):
multiplier = 5
return self.value * multiplier
What is multiplier? - Answers - local variable
Private data is commonly used inside classes. In order to change this private data a
method can be created. What is the term for this type of method? Choose the most
correct answer. - Answers - setter
class Widget:
def __init__(self, value):
self.value = value
def getMultiple(self, multiplier):
return self.value * multiplier
def __performCalculation(self):
self.value += 10
What is __performCalculation? - Answers - private method
str1 = "Hello"
str2 = "Hello"
print(id(str1))
print(id(str2))
***********
ANSWERS
Fill in the blanks in the correct order.
A _______ is a template or blueprint that is used to create a(n) ____________ of the
same type. - Answers - class, object
A ________________ is used to create an instance of a class. - Answers - constructor
What is the name of the method that is defined to customize an object, and is
automatically called when an instance of a class is created? - Answers - __init__
class A:
def __init__(self):
self.x = 1
self.__y = 2
def getY(self):
return self.__y
a = A()
print(a.__y)
************************What is printed? - Answers - Nothing because y is private
______________________ is way to diagram classes to give a visual representation. -
Answers - UML
What does UML stand for? - Answers - Unified Modeling Language
By convention the word ______________ is used as the first formal parameter of an
instance method. - Answers - self
Which of the following describes Procedural Programming? - Answers - data and
function are separate
- Separation of class implementation from the use of a class
- The implementation details are hidden from the user
- The user knows what the result is, but not how it happens
- A class is like a black box - Answers - Encapsulation and abstraction
What is the name of the built-in function that will return the number of characters in a
string or the number of elements in a list? - Answers - len
, What is the symbol for the Access Operator?
Correct! - Answers - .
Writing code to make it possible to use the // (integer division) symbol on an object is
called - Answers - operator overloading
What is the method that can be defined to change the meaning of the - (minus) symbol?
- Answers - __sub__
class Widget:
def __init__(self, value):
self.value = value
def getMultiple(self, multiplier):
return self.value * multiplier
What is getMultiple? - Answers - method
class Widget:
def __init__(self, value):
self.value = value
def getMultiple(self, multiplier):
multiplier = 5
return self.value * multiplier
What is multiplier? - Answers - local variable
Private data is commonly used inside classes. In order to change this private data a
method can be created. What is the term for this type of method? Choose the most
correct answer. - Answers - setter
class Widget:
def __init__(self, value):
self.value = value
def getMultiple(self, multiplier):
return self.value * multiplier
def __performCalculation(self):
self.value += 10
What is __performCalculation? - Answers - private method
str1 = "Hello"
str2 = "Hello"
print(id(str1))
print(id(str2))
***********