Deck 9: Design With Classes

ملء الشاشة (f)
exit full mode
سؤال
Python programmers typically capitalize their own class names to distinguish them from variable names.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
To overload an arithmetic operator, you just define a new method using the appropriate method name.
سؤال
Inheritance allows several different classes to use the same general method names.
سؤال
For data that are owned by individual objects, you must use class variables.
سؤال
The Python interpreter picks out equality from the other comparisons by looking for an __equals__ method when it encounters the == and != operators.
سؤال
Operator overloading is an example of an abstraction mechanism.
سؤال
Python has a built-in type for rational numbers called rational.
سؤال
A method automatically returns the value None when it includes no return statement.
سؤال
The scope of an instance variable is the entire module.
سؤال
If the parenthesized parent class name is omitted from the class definition, the new class is automatically made a subclass of self.
سؤال
Most object-oriented languages require the programmer to master the following techniques: data encapsulation, inheritance, and abstraction.
سؤال
The function call str(s) is equivalent to the method call s.__str__().
سؤال
In general, you should use class variables only for symbolic constants or to maintain data held in common by all objects of a class.
سؤال
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.
سؤال
Inheritance allows a class to automatically reuse and extend the code of similar but more general classes.
سؤال
The code x % y is actually shorthand for the code __mod__(x, y).
سؤال
The attributes of an object are represented as instance datum.
سؤال
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.
سؤال
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.
سؤال
A class variable is visible to all instances of a class and does not vary from instance to instance.
سؤال
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.
سؤال
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.
سؤال
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
سؤال
Although Python is considered an object-oriented language, its syntax does not enforce data encapsulation.
سؤال
It is not usual to bother subclassing unless the two classes share a substantial amount of abstract behavior.
سؤال
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.
سؤال
The str method is a good example of a polymorphic method that appears throughout Python's system of classes.
سؤال
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.
سؤال
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.
سؤال
Unlike other object-oriented languages, Python does not support polymorphic methods.
سؤال
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__
سؤال
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
سؤال
What are the two parts of a rational number? (Choose two.)

A) dominator
B) denominator
C) numerator
D) terminator
سؤال
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
سؤال
Objects in the natural world and objects in the world of artifacts can be classified using inheritance hierarchies.
سؤال
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.
سؤال
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__
سؤال
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
سؤال
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
سؤال
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.
سؤال
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.
سؤال
The attributes of an object are represented as what type of variables?

A) state variables
B) substance variables
C) instance variables
D) self variables
سؤال
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
سؤال
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.
سؤال
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
سؤال
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
سؤال
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.
سؤال
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.
سؤال
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.
سؤال
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 Deck
1/50
auto play flashcards
العب
simple tutorial
ملء الشاشة (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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
6
Operator overloading is an example of an abstraction mechanism.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
7
Python has a built-in type for rational numbers called rational.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
8
A method automatically returns the value None when it includes no return statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
9
The scope of an instance variable is the entire module.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
11
Most object-oriented languages require the programmer to master the following techniques: data encapsulation, inheritance, and abstraction.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
12
The function call str(s) is equivalent to the method call s.__str__().
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
15
Inheritance allows a class to automatically reuse and extend the code of similar but more general classes.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
16
The code x % y is actually shorthand for the code __mod__(x, y).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
17
The attributes of an object are represented as instance datum.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
20
A class variable is visible to all instances of a class and does not vary from instance to instance.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
24
Although Python is considered an object-oriented language, its syntax does not enforce data encapsulation.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
25
It is not usual to bother subclassing unless the two classes share a substantial amount of abstract behavior.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
27
The str method is a good example of a polymorphic method that appears throughout Python's system of classes.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
30
Unlike other object-oriented languages, Python does not support polymorphic methods.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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__
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
33
What are the two parts of a rational number? (Choose two.)

A) dominator
B) denominator
C) numerator
D) terminator
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
35
Objects in the natural world and objects in the world of artifacts can be classified using inheritance hierarchies.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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__
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.