Chapter 07 – An Introduction to Programming using Python Schneider
Download file with the answers
Chapter 07 - An Introduction to Programming using Python Schneider
1 file(s) 111.87 KB
If you are not a member register here to download this file
Chapter 7
1. When as much implementation detail as possible in a program is hidden, it is called __________.
a. data hiding
b. polymorphism
c. inheritance
d. implementation masking
2. What type of classes in Python are str, int, float, list, tuple, dictionary and set?
a. built-in
b. primitive
c. polymorphic
d. object oriented
3. A specific literal from a built-in classes is called a(n) __________.
a. instance
b. primitive
c. object
d. value
4. What is the output of the following Python code?
K = [“Larry”, “Curly”, “Mo”]
print(type(K))
a.
b.
c.
d. str
5. Which method provides a customized way to represent the state of an object as a string?
a. _ _ str _ _
b. _ _ init _ _
c. _ _ print _ _
d. print
6. What type of methods are used to assign new values to the instance variables?
a. mutator
b. assignment
c. accessor
d. initializer
7. What type of methods are used to retrieve the values of instance variables?
a. accessor
b. mutator
c. retriever
d. value
8. What type of method is called when an object is created?
a. constructor
b. mutator
c. initializer
d. accessor
9. Methods in a class have self as their __________ parameter.
a. first
b. last
c. default
d. only
10. Class definitions can contain __________ methods.
a. an unlimited number of
b. only accessor and mutator
c. one constructor, two accessor and two mutator
d. a maximum of 10
11. The statement
object = className(arg1, arg2, …)
is said to __________ an object.
a. instantiate
b. inherit
c. encapsulate
d. polymorphize
12. The process of bundling together data and methods while hiding the implementation of the methods is called __________.
a. encapsulation
b. instantiation
c. polymorphism
d. inheritance
13. What is the feature called in Python that allows us to define a new class that is a modified version of an existing class?
a. inheritance
b. encapsulation
c. data hiding
d. polymorphism
14. When using inheritance to define a new class, the new class is called a __________.
a. subclass
b. child class
c. derived class
d. all of the above
15. In inheritance, the existing class that is used to create a subclass from is called a __________.
a. superclass
b. parent class
c. base class
d. all of the above
16. If a method defined in the subclass has the same name as a method in its superclass, the child’s method will __________.
a. override the parent’s method
b. be ignored
c. cause a Throwback error
d. confuse the programmer
17. When two classes use the same method name, it is called __________.
a. polymorphism
b. inheritance
c. encapsulation
d. duplication
True/False (17)
1. All lists are instances of the class list.
Answer: true
2. Because each string holds its own value, all strings do not have the same methods.
Answer: false
3. Each object of a class will have the same values.
Answer: false
4. Class names must follow the same naming rules as variables.
Answer: true
5. The _ _ init _ _ method must be explicitly called by the programmer when a new object is created.
Answer: false
6. Instance variables are also called properties of an object.
Answer: true
7. A class is a template from which objects are created.
Answer: true
8. Instance variables may only be seen by the method in which they are used.
Answer: false
9. It is a poor programming practice to directly access class instance variables outside of the class.
Answer: true
10. A class must contain at least one accessor method.
Answer: false
11. A class must contain at least one mutator method.
Answer: false
12. Items in a list may not include a user-defined class.
Answer: false
13. The parameter self is a reserved word in Python.
Answer: false
14. A child class that is a specialization of the parent class is said to have an “is-a” relationship.
Answer: true
15. Child classes normally have all the characteristics of their parents, but less functionality.
Answer: false
16. The isinstance function can be applied to both built-in and user-defined functions.
Answer: true
17. A subclass can change the behavior of an inherited method.
Answer: true
Short Answer (6)
1. Explain the purpose of the self parameter in a method that is defined in a class.
Answer: This parameter references the object created so that the method know which object to operator on.
2. Give two reasons why instance variables should only be accessed from outside of a class definition via class methods?
Answer: a) Validity-checking code can be inserted into methods to make programs more robust.
b) One of the objectives of object-oriented programming is to hide implementation
details of methods from the users of the class.
3. What does the following line of Python code return?
isinstance( [ ], list)
Answer: True
4. What does the following line of Python code return?
isinstance( { }, set)
Answer: False
5. What does the following line of Python code return?
isinstance( ( ), tuple)
Answer: True
6. Explain the purpose of polymorphism.
Answer: Polymorphism gives you the ability to use the same syntax for objects of different types.
Leave a reply