Question: Consider the following code segment: def mutate(self, newType) : self._type = newType self._mutations = self._mutations + 1 What is the name of the local variable
Consider the following code segment:
def mutate(self, newType) :
self._type = newType
self._mutations = self._mutations + 1
What is the name of the local variable in it:
Question options:
|
| mutate |
|
| _mutations |
|
| newType |
|
| _type |
Which of the following is NOT a pattern used to help design the data representation of a class?
Question options:
|
| An instance variable for thte total is updated in methods that increase or decrease the total amount |
|
| An object reference specifies the location of an object |
|
| An object can collect other objects in a list |
|
| To model a moving object, you need to store and update its position |
Given the following code snippet, how can you test if they reference the same object (or does not refer to any object)?
bankAcct2 = bankAcct
Question options:
|
|
if bankAcct == bankAcct2 : print("The variables are aliases") |
|
|
if bankAcct is bankAcct2 : print("The variables are aliases") |
|
|
if bankAcct is not bankAcct2 : print("The variables are aliases") |
|
|
if bankAcct.equals(bankAcct2) : print("The variables are aliases") |
Which statement determines if the middleInit variable is empty or does not refer to any object?
Question options:
|
|
if middleInit is None : print("No middle initial") |
|
|
if middleInit is not None : print("No middle initial") |
|
|
if middleInit == None : print("No middle initial") |
|
|
if middleInit != None : print("No middle initial") |
Recall the Cash Register class developed in the textbook. What is output by the following code segment?
from cashregister2 import CashRegister
reg1 = CashRegister()
reg2 = reg1
reg1.addItem(3.00)
reg1.addItem(5.00)
reg2.clear()
print(reg1.getCount())
Question options:
|
| 0 |
|
| 1 |
|
| 2 |
|
| The program terminates with a runtime error |
Recall the Cash Register class developed in the textbook. What is output by the following code segment?
from cashregister2 import CashRegister
reg1 = CashRegister()
reg1.addItem(3.00)
reg2 = reg1
reg1.addItem(5.00)
print(reg2.getCount())
Question options:
|
| 0 |
|
| 1 |
|
| 2 |
|
| The program terminates with a runtime error |
Consider a class that represents a hardware device. The device can be in one of two states: Plugged in, or unplugged. Which of the following class definitions is best for this situation?
Question options:
|
|
PLUGGED_IN = 0 UNPLUGGED = 1
class Device : def __init__(self) : . . . |
|
|
class Device : PLUGGED_IN = 0 UNPLUGGED = 1
def __init__(self) : . . . |
|
|
class Device : def __init__(self) : PLUGGED_IN = 0 UNPLUGGED = 1 . . . |
|
|
class Device : def __init__(self) : self.PLUGGED_IN = 0 self.UNPLUGGED = 1 . . . |
Consider the following class:
class Pet:
def __init__(self, name):
self._name = name
def getName(self):
____________________
What line of code should be placed in the blank to complete the getName accessor method that is supposed to return the pet's name?
Question options:
|
| return |
|
| return _name |
|
| return self |
|
| return self._name |
Which method below would be considered a mutator method?
Question options:
|
|
getCount() |
|
|
addItem() |
|
|
getTotal() |
|
|
printItem() |
Consider the following code segment:
bankAcct = BankAccount("Fisher", 1000.00)
bankAcct2 = bankAcct
What is the relationship between bankAcct and bankAcct2?
Question options:
|
| bankAcct and bankAcct2 are self references |
|
| bankAcct and bankAcct2 are aliases for the same object reference |
|
| bankAcct and bankAcct2 are NONE references |
|
| bankAcct and bankAcct2 are separate references |
Consider the following class:
class Fruit : # Line 1
def getColor(self) : # Line 2
retval = self._color # Line 3
return retval # Line 4
Which line(s) are part of the public interface for the class?
Question options:
|
| Only line 1 |
|
| Only line 2 |
|
| Only lines 2 and 3 |
|
| Only lines 3 and 4 |
Which of the follow code segments could be used to help test the getColor method from the Fruit class?
Question options:
|
|
print(f.getColor()) print("Expected: Yellow") |
|
|
print("Yellow") print("Expected: Yellow") |
|
|
print(f.getColor()) print("Expected:", f.getColor()) |
|
|
print("Yellow") print("Expected:", f.getColor()) |
Which of the following is NOT true about instance methods for a class?
Question options:
|
| The object on which a method is applied is automatically passed to the self parameter variable of the method |
|
|
In a method, you access instance variables through the self parameter variable |
|
|
A class variable belongs to the class, not to any instance of the class |
|
|
The accessor and mutator methods are automatically called when an object is created |
Which of the following is NOT a true statement regarding object-oriented programming?
Question options:
|
| Object oriented programming views the program as a list of actions to perform. |
|
|
Object oriented programs usually contain different types of objects, each corresponding to a particular kind of complex data, real-world object or concept. |
|
|
Object oriented programming is a style where tasks are solved by collaborating objects. |
|
|
Object oriented programs are organized around "objects" rather than "actions" and "data" rather than "logic". |
Which of the following patterns can be used for designing your class to update the balance of a bank account?
Question options:
|
| Keeping a total |
|
| Counting events |
|
| Collecting values |
|
| Managing properties of an object |
The following two objects are created from the Counter class: studentCounter, and teacherCounter to represent the total number of students and the total number of teachers respectively. If the Counter class contains an instance variable, _num, that is initialized to zero and increases every time the user executes the add method, what is stored in each object's instance variable after the following code snippet executes?
studentCounter.add()
teacherCounter.add()
studentCounter.add()
Question options:
|
| studentCounter : 3, teacherCounter : 3 |
|
| studentCounter : 2, teacherCounter : 1 |
|
| studentCounter : 1, teacherCounter : 2 |
|
| studentCounter : 1, teacherCounter : 1 |
Consider the following class which is used to represent a polygon consisting of an arbitrary number of (x, y) points:
class Polygon :
def __init__(self) :
self._x_points = []
self._y_points = []
Which of the following code segments is the correct implementation for the addPoint method that adds another point to the polygon?
Question options:
|
|
def addPoint(self, x, y) : self._points.append(x, y) |
|
|
def addPoint(self, x, y) : self._x_points.append(x) self._y_points.append(y) |
|
|
def addPoint(self, x, y) : self._x_points = x self._y_points = y |
|
|
def addPoint(self, x, y) : self._x_points = [x] self._y_points = [y] |
In the following example, which data is considered instance data?
You are assigned the task of writing a program that calculates payroll for a small company. To get started the program should do the following:
Add new employees including their first and last name and hourly wage
Ask for the number of hours worked
Calculate payroll (applying 1.5 for any hours greater than 40)
Print a report of all employees' salary for the week, total of all hours and total of all salaries
Question options:
|
|
firstName, lastName, hoursWorked, hourlyWage |
|
|
firstName, lastName, hoursWorked, hourlyWage, payrollAmount |
|
|
firstName, lastName, hoursWorked, hourlyWage, totalHours, totalSalary |
|
|
firstName, lastName, hoursWorked, hourlyWage, payrollAmount, totalHours, totalSalary |
Consider the following class:
class Counter :
def getValue(self) :
return self._value
def click(self) :
self._value = self._value + 1
def unClick(self) :
self._value = self._value - 1
def reset(self) :
self._value = 0
Which method(s) are mutators?
Question options:
|
| Only reset |
|
| Only click and unClick |
|
| Only click, unClick and reset |
|
| All four methods are mutators |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
