Chapter 10 Classes and Object-Oriented Programming Flashcards
Which method is automatically called when you pass an object as an argument to the print function?
a. __init__
b. __obj__
c. __str__
d. __state__
__str__
Chapter 10 Q
Which attributes belong to a specific instance of a class?
a. instance
b. object
c. data
d. self
instance
Chapter 10 Q (page# 510)
What type of programming contains class definitions?
a. top-down
b. modular
c. procedural
d. object-oriented
object-oriented
Chapter 10 Q
Procedures operate on data items that are separate from the procedures.
True or False?
True
Chapter 10 Q
A class can be thought of as a blueprint that can be used to create an object. True or False?
True
Chapter 10 Q
Which of the first line needed when creating a class named Worker?
a. def__init__(self):
b. import random
c. class Worker:
d. def worker_pay(self):
class Worker:
Chapter 10 Q (page# 494)
To create a class, you write a class definition. A class definition is a set of statements that define a class’s methods and data attributes.
The self parameter is required in every method of a class.
True or False?
True
Chapter 10 Q
A mutator method has no control over the way that a class’s data attributes are notified.
True or False?
False
Chapter 10 Q (page# 515) A method that stores a value in a data attribute or changes the value of a data attribute in some other way is known as a mutator method. Mutator methods "can control" the way that a class's data attributes are notified. When a code outside the class needs to change the value of an object's data attribute, it typically calls a mutator and passes the new value as an argument.
nt.
Which methods is automatically executed when an instance of a class is created in memory?
a. __obj__
b. __str__
c. __state__
d. __init__
__init__
Chapter 10 Q (page# 496)
Python class have a special method named _ _init_ _, which is automatically executed when an instance of the class is created in memory. The _ _init_ _ method is commonly known as an initializer method because it initializes the object's data attributes.
When an object is passed as an argument, ___ is passed into the parameter variable.
a. Objects cannot be passed as arguments.
b. a copy of the object
c. a reference to the object
d. a reference to the object’s state.
a reference to the object
Chapter 10 Q (page# 518)
When you pass an object as an argument, the thing that is passed into the parameter variable is a reference to that object. As a result, the function or method that receives the object as an argument has access to the actual object.