Deck 9: Design With Classes

Full screen (f)
exit full mode
Question
Python programmers typically capitalize their own class names to distinguish them from variable names.
Use Space or
up arrow
down arrow
to flip the card.
Question
To overload an arithmetic operator, you just define a new method using the appropriate method name.
Question
Inheritance allows several different classes to use the same general method names.
Question
For data that are owned by individual objects, you must use class variables.
Question
The Python interpreter picks out equality from the other comparisons by looking for an __equals__ method when it encounters the == and != operators.
Question
Operator overloading is an example of an abstraction mechanism.
Question
Python has a built-in type for rational numbers called rational.
Question
A method automatically returns the value None when it includes no return statement.
Question
The scope of an instance variable is the entire module.
Question
If the parenthesized parent class name is omitted from the class definition, the new class is automatically made a subclass of self.
Question
Most object-oriented languages require the programmer to master the following techniques: data encapsulation, inheritance, and abstraction.
Question
The function call str(s) is equivalent to the method call s.__str__().
Question
In general, you should use class variables only for symbolic constants or to maintain data held in common by all objects of a class.
Question
Any object can be pickled before it is saved to a file, and then unpickled as it is loaded from a file into a program.
Question
Inheritance allows a class to automatically reuse and extend the code of similar but more general classes.
Question
The code x % y is actually shorthand for the code __mod__(x, y).
Question
The attributes of an object are represented as instance datum.
Question
To reduce a rational number to its lowest terms, you first compute the greatest common divisor (GCD) of the numerator and the denominator, using Euclid's algorithm.
Question
If the statements in the try clause raise no exceptions, the except clause is skipped and control proceeds to the end of the try-except statement.
Question
A class variable is visible to all instances of a class and does not vary from instance to instance.
Question
What statement is an accurate description of the concept of inheritance in object-oriented programming?

A) Inheritance is the restricting of the manipulation of an object's state by external users to a set of method calls.
B) Inheritance is allowing a class to automatically reuse and extend the code of a similar but more general class.
C) Inheritance is the use of code that is capable of making changes to itself during the execution process.
D) Inheritance is allowing the several different classes to use the same general method names.
Question
What statement is an accurate description of the concept of polymorphism in object-oriented programming?

A) Polymorphism is the restricting of the manipulation of an object's state by external users to a set of method calls.
B) Polymorphism is allowing a class to automatically reuse and extend the code of a similar but more general class.
C) Polymorphism is the use of code that is capable of making changes to itself during the execution process.
D) Polymorphism is allowing the several different classes to use the same general method names.
Question
At the top, or root of the class hierarchy is the most abstract class. What is the name of this class?

A) root
B) object
C) parentClass
D) Main
Question
Although Python is considered an object-oriented language, its syntax does not enforce data encapsulation.
Question
It is not usual to bother subclassing unless the two classes share a substantial amount of abstract behavior.
Question
You are utilizing the pickle.load function to load objects into a program from a file. However, your program raises an exception as soon as the end of the file is reached. What must you do?

A) Use an if-else statement to check if the load function is at the end of the file.
B) Use a nested loop to run the pickle.load function line by line.
C) Use a try-except statement to catch the exception and continue with the program.
D) Use the pickle.len() function to determine the size of the file, then pass the size to the pickle.load() function using the size key.
Question
The str method is a good example of a polymorphic method that appears throughout Python's system of classes.
Question
In the context of Python objects, what does the pickling process do?

A) It preserves objects by storing them in memory.
B) It preserves objects by storing them to a file.
C) It preserves objects by creating a sqlite database.
D) It preserves objects by adding them to the calling Python script file.
Question
What is the __str__ method used for?

A) It builds and returns a string representation of an object's state.
B) It is used to determine if a class attribute is a string.
C) It is used to initiate string values during instantiation.
D) It converts a string attribute within a class.
Question
Unlike other object-oriented languages, Python does not support polymorphic methods.
Question
If you wanted to overload the greater than or equal operator, what method name should you define?

A) __gte__
B) __gt__
C) __ge__
D) __geq__
Question
What function do you use to save an object utilizing the pickle module?

A) pickle.save
B) pickle.jar
C) pickle.dump
D) pickle.store
Question
What are the two parts of a rational number? (Choose two.)

A) dominator
B) denominator
C) numerator
D) terminator
Question
What is the process in which the Python virtual machine recycles its storage known as?

A) garbage collection
B) trash expunging
C) data dumping
D) tombstoning
Question
Objects in the natural world and objects in the world of artifacts can be classified using inheritance hierarchies.
Question
In Python, when does an object reach the end of its life?

A) When its timeout value has expired.
B) When it has been terminated by the destroy method.
C) When it has passed the last statement that uses it.
D) When it can no longer be referred to by the program that created it.
Question
What method is known as a class's constructor, because it is run automatically when a user instantiates the class?

A) __start__
B) __build__
C) __main__
D) __init__
Question
When the pickle.load function reaches the end of a file, what type of exception is raised?

A) IOError
B) EOFError
C) DataError
D) FileError
Question
What are the two access modes that are used when opening a file for input and output when pickling? (Choose two.)

A) r
B) rb
C) w
D) wb
Question
How could you overload the addition operator in the Python language?

A) You create a def statement with an asterisk, then specify math.__add__ as the method name.
B) You create a new class with the same name as the arithmetic class, and define the __add__ method.
C) You declare a new method with the same name, __add__, and define the method.
D) You create a Python script named __add__.py, and then define the new method in that script, then import it.
Question
What type of programming is defined by the term "imperative programming"?

A) Programming such that classes can be defined for objects and reused to define similar objects.
B) Programming that involves the use of input and output statements, assignment statements, and control statements for selection and iteration.
C) Programming that uses cooperating subprograms to solve problems.
D) Programming that views a program as a set of cooperating functions.
Question
The attributes of an object are represented as what type of variables?

A) state variables
B) substance variables
C) instance variables
D) self variables
Question
What can be used to describe and document the analysis and design of complex software systems?

A) Class Diagraming Language
B) Programming Structural Language
C) Direct Modeling Language
D) Unified Modeling Language
Question
What effect does using the model/view pattern of design have?

A) It divides the roles and responsibilities of the system between data management and user interface display.
B) It combines the roles and responsibilities of the system between data management and user interface display.
C) It involves the user in the defining of how data will be modeled by a program.
D) It involves the creation of a model GUI environment, and then involves the creation of views for the user to choose from.
Question
What concept within object-oriented programming involves the restriction of the manipulation of an object's state by external users to a set of method calls?

A) inheritance
B) polymorphism
C) data encapsulation
D) data modeling
Question
What two terms are used for the methods that are used to observe or modify the state of an object, respectively?

A) accessors
B) ingressors
C) modifiers
D) mutators
Question
As a rule of thumb, when should you include an __eq__ method in a class?

A) Always, because the comparison for equality is not compatible with classes.
B) Whenever a comparison for equality uses criterion other than object identity.
C) Only when you need to be able to make a comparison based on object identity.
D) Only if you plan to export the class as part of a module.
Question
What type of programming is defined by the term "functional programming"?

A) Programming utilizing cooperative subprograms to solve problems.
B) Programming using input and output statements, assignment statements, and control statements for selection and iteration.
C) Programming such that classes can be defined for objects and reused to define similar objects.
D) Programming using a set of cooperating functions rather than relying on assignment.
Question
What type of programming is defined by the term "procedural programming"?

A) Programming utilizing cooperative subprograms to solve problems.
B) Programming using input and output statements, assignment statements, and control statements for selection and iteration.
C) Programming such that classes can be defined for objects and reused to define similar objects.
D) Programming using a set of cooperating functions rather than relying on assignment.
Question
Regarding class variables, what statement is accurate?

A) A class variable is only visible to a single instance of a class.
B) A class variable is visible only to methods inside a class.
C) A class variable is visible to all instances of a class, but can vary from instance to instance.
D) A class variable is visible to all instances of a class, and does not vary from instance to instance.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 9: Design With Classes
1
Python programmers typically capitalize their own class names to distinguish them from variable names.
True
2
To overload an arithmetic operator, you just define a new method using the appropriate method name.
True
3
Inheritance allows several different classes to use the same general method names.
False
4
For data that are owned by individual objects, you must use class variables.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
The Python interpreter picks out equality from the other comparisons by looking for an __equals__ method when it encounters the == and != operators.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
Operator overloading is an example of an abstraction mechanism.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
Python has a built-in type for rational numbers called rational.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
A method automatically returns the value None when it includes no return statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
The scope of an instance variable is the entire module.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
If the parenthesized parent class name is omitted from the class definition, the new class is automatically made a subclass of self.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
Most object-oriented languages require the programmer to master the following techniques: data encapsulation, inheritance, and abstraction.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
The function call str(s) is equivalent to the method call s.__str__().
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
In general, you should use class variables only for symbolic constants or to maintain data held in common by all objects of a class.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
Any object can be pickled before it is saved to a file, and then unpickled as it is loaded from a file into a program.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
Inheritance allows a class to automatically reuse and extend the code of similar but more general classes.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
The code x % y is actually shorthand for the code __mod__(x, y).
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
The attributes of an object are represented as instance datum.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
To reduce a rational number to its lowest terms, you first compute the greatest common divisor (GCD) of the numerator and the denominator, using Euclid's algorithm.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
If the statements in the try clause raise no exceptions, the except clause is skipped and control proceeds to the end of the try-except statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
A class variable is visible to all instances of a class and does not vary from instance to instance.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
What statement is an accurate description of the concept of inheritance in object-oriented programming?

A) Inheritance is the restricting of the manipulation of an object's state by external users to a set of method calls.
B) Inheritance is allowing a class to automatically reuse and extend the code of a similar but more general class.
C) Inheritance is the use of code that is capable of making changes to itself during the execution process.
D) Inheritance is allowing the several different classes to use the same general method names.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
What statement is an accurate description of the concept of polymorphism in object-oriented programming?

A) Polymorphism is the restricting of the manipulation of an object's state by external users to a set of method calls.
B) Polymorphism is allowing a class to automatically reuse and extend the code of a similar but more general class.
C) Polymorphism is the use of code that is capable of making changes to itself during the execution process.
D) Polymorphism is allowing the several different classes to use the same general method names.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
At the top, or root of the class hierarchy is the most abstract class. What is the name of this class?

A) root
B) object
C) parentClass
D) Main
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
Although Python is considered an object-oriented language, its syntax does not enforce data encapsulation.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
It is not usual to bother subclassing unless the two classes share a substantial amount of abstract behavior.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
You are utilizing the pickle.load function to load objects into a program from a file. However, your program raises an exception as soon as the end of the file is reached. What must you do?

A) Use an if-else statement to check if the load function is at the end of the file.
B) Use a nested loop to run the pickle.load function line by line.
C) Use a try-except statement to catch the exception and continue with the program.
D) Use the pickle.len() function to determine the size of the file, then pass the size to the pickle.load() function using the size key.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
The str method is a good example of a polymorphic method that appears throughout Python's system of classes.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
In the context of Python objects, what does the pickling process do?

A) It preserves objects by storing them in memory.
B) It preserves objects by storing them to a file.
C) It preserves objects by creating a sqlite database.
D) It preserves objects by adding them to the calling Python script file.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
What is the __str__ method used for?

A) It builds and returns a string representation of an object's state.
B) It is used to determine if a class attribute is a string.
C) It is used to initiate string values during instantiation.
D) It converts a string attribute within a class.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
Unlike other object-oriented languages, Python does not support polymorphic methods.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
If you wanted to overload the greater than or equal operator, what method name should you define?

A) __gte__
B) __gt__
C) __ge__
D) __geq__
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
What function do you use to save an object utilizing the pickle module?

A) pickle.save
B) pickle.jar
C) pickle.dump
D) pickle.store
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
What are the two parts of a rational number? (Choose two.)

A) dominator
B) denominator
C) numerator
D) terminator
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
What is the process in which the Python virtual machine recycles its storage known as?

A) garbage collection
B) trash expunging
C) data dumping
D) tombstoning
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
Objects in the natural world and objects in the world of artifacts can be classified using inheritance hierarchies.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
In Python, when does an object reach the end of its life?

A) When its timeout value has expired.
B) When it has been terminated by the destroy method.
C) When it has passed the last statement that uses it.
D) When it can no longer be referred to by the program that created it.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
What method is known as a class's constructor, because it is run automatically when a user instantiates the class?

A) __start__
B) __build__
C) __main__
D) __init__
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
When the pickle.load function reaches the end of a file, what type of exception is raised?

A) IOError
B) EOFError
C) DataError
D) FileError
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
What are the two access modes that are used when opening a file for input and output when pickling? (Choose two.)

A) r
B) rb
C) w
D) wb
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
How could you overload the addition operator in the Python language?

A) You create a def statement with an asterisk, then specify math.__add__ as the method name.
B) You create a new class with the same name as the arithmetic class, and define the __add__ method.
C) You declare a new method with the same name, __add__, and define the method.
D) You create a Python script named __add__.py, and then define the new method in that script, then import it.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
What type of programming is defined by the term "imperative programming"?

A) Programming such that classes can be defined for objects and reused to define similar objects.
B) Programming that involves the use of input and output statements, assignment statements, and control statements for selection and iteration.
C) Programming that uses cooperating subprograms to solve problems.
D) Programming that views a program as a set of cooperating functions.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
The attributes of an object are represented as what type of variables?

A) state variables
B) substance variables
C) instance variables
D) self variables
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
What can be used to describe and document the analysis and design of complex software systems?

A) Class Diagraming Language
B) Programming Structural Language
C) Direct Modeling Language
D) Unified Modeling Language
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
What effect does using the model/view pattern of design have?

A) It divides the roles and responsibilities of the system between data management and user interface display.
B) It combines the roles and responsibilities of the system between data management and user interface display.
C) It involves the user in the defining of how data will be modeled by a program.
D) It involves the creation of a model GUI environment, and then involves the creation of views for the user to choose from.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
What concept within object-oriented programming involves the restriction of the manipulation of an object's state by external users to a set of method calls?

A) inheritance
B) polymorphism
C) data encapsulation
D) data modeling
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
What two terms are used for the methods that are used to observe or modify the state of an object, respectively?

A) accessors
B) ingressors
C) modifiers
D) mutators
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
As a rule of thumb, when should you include an __eq__ method in a class?

A) Always, because the comparison for equality is not compatible with classes.
B) Whenever a comparison for equality uses criterion other than object identity.
C) Only when you need to be able to make a comparison based on object identity.
D) Only if you plan to export the class as part of a module.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
What type of programming is defined by the term "functional programming"?

A) Programming utilizing cooperative subprograms to solve problems.
B) Programming using input and output statements, assignment statements, and control statements for selection and iteration.
C) Programming such that classes can be defined for objects and reused to define similar objects.
D) Programming using a set of cooperating functions rather than relying on assignment.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
What type of programming is defined by the term "procedural programming"?

A) Programming utilizing cooperative subprograms to solve problems.
B) Programming using input and output statements, assignment statements, and control statements for selection and iteration.
C) Programming such that classes can be defined for objects and reused to define similar objects.
D) Programming using a set of cooperating functions rather than relying on assignment.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
Regarding class variables, what statement is accurate?

A) A class variable is only visible to a single instance of a class.
B) A class variable is visible only to methods inside a class.
C) A class variable is visible to all instances of a class, but can vary from instance to instance.
D) A class variable is visible to all instances of a class, and does not vary from instance to instance.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 50 flashcards in this deck.