Questions with Correct Answers
Which of the following statements is true about class attributes? ✅-the values of an
object's attributes are called the state of that object
-attributes can be any kind of Python data types
-object attributes can be read or updated by using "dot notation" - for example, for an
object s1, s1.name = 'Mary' resets object s1's name to 'Mary'.
-attributes belonging to an object are referenced by methods inside the class by using a
common keyword prefix, customarily "self"
Which of the following are true about classes in Python? ✅-A class definition is only a
blueprint and is not executed by the Python interpreter until used by other code
-A class consists of attributes (data) and methods (functions or behaviors
-When objects of a class are created the "__init__( )" method accepts parameters that
are used to assign starting values for some of its attributes.
Which of the following are true about class methods? ✅-methods are defined using the
same keyword used to define functions, e.g. "def"
-methods are often referred to as the class behaviors
-methods may use any valid Python statements
-a method called "getDay" can be defined by the statement "def getDay (self):"
-a class must always have a method called "__init__( )" if it is to be used to create
objects of the class's type
-a method uses attributes that belong to the object in which it's defined by using a
common prefix such as "self" - for example, "self.day" to read or update object attribute
"day"
Which statements are true about attributes? ✅-instance attributes belong to a
particular class object and each object has its own copy or value
-class attributes are accessed by using class name-dot-attribute, e.g.
"Date.currentYear" for class attribute "currentYear"
-class attributes have only one copy or value for all objects of that class
Which of the following statements is true concerning the security or privacy aspects of
the Java and Python languages? ✅Java's security is stronger, more secure, than
Python's
How might you change the Date class, as described in the various lectures, to modify it
so its objects could be useful when added into an appointment book class container?
Check all that would improve the usability of the Date class for this requirement. ✅-
Add an attribute to represent an appointment time
-Add an attribute to record the name of the party with whom an appointment is with
, -Add an attribute to record the location of the appointment
-Add a method to display all appointments for a given day or time period
-Add methods to allow appointments to be added, removed, or updated
A method whose purpose is to allow external code the ability to change a protected
attribute that's part of that method's class is what type of method? ✅setter
In Python object-oriented programming, inheritance involves: ✅creating a new class by
citing the name of another class whose attributes and methods become part of the new
class
Which of the following are true about UML? Check all that are true. ✅-UML is an
abbreviation for "Unified Modeling Language"
-UML class diagrams are normally drawn as rectangles divided into three areas
-UML class diagrams show the class name in the uppermost area of the diagram and
methods in the lowest area
-UML diagrams may contain multiple class diagrams showing relationships among
classes in a system
In creating a UML diagram for somce class you want to include a method that allows an
attribute called "factor" to be reset. You know that "factor" will be a string data type and
that the method should return True if the update is successful, and False if not. Which of
the following actions will correctly add the method information to the UML diagram? No
privacy or security settings need to be shown on this diagram. ✅enter
"setfactor(string): Boolean" in the bottom area of the diagram
A subclass that inherits a method from a superclass can do the following (check all that
apply): ✅-execute the inherited method without specifically defining its code in its own
definition
-override the inherited method, but execute the superclass's method by running "super(
). {method name}"
-override an inherited method by providing a method with the same name as the
parent's method
(True/False) Exceptions are events such as errors detected during program execution
that alter, or interrupt, the program's flow. ✅True
Below is part of a file with text data. How might one process the file using a Python
program? Check all the following that would be used in the processing.
AL, Alabama, Montgomery
CO, Colorado, Denver
DE, Delaware, Dover
GA, Georgia, Atlanta
MT, Montana, Helena
RI, Rhode Island, Providence ✅-open the file in read ("r") mode