Chapter 10 Classes and Object-Oriented Programming Flashcards

1
Q

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__

A

__str__

Chapter 10 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which attributes belong to a specific instance of a class?

a. instance
b. object
c. data
d. self

A

instance

Chapter 10 Q (page# 510)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What type of programming contains class definitions?

a. top-down
b. modular
c. procedural
d. object-oriented

A

object-oriented

Chapter 10 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Procedures operate on data items that are separate from the procedures.
True or False?

A

True

Chapter 10 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
A class can be thought of as a blueprint that can be used to create an object.
True or False?
A

True

Chapter 10 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
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):

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The self parameter is required in every method of a class.

True or False?

A

True

Chapter 10 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A mutator method has no control over the way that a class’s data attributes are notified.
True or False?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which methods is automatically executed when an instance of a class is created in memory?

a. __obj__
b. __str__
c. __state__
d. __init__

A

__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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly