Question: Question 1 Which statement successfully creates a new Apple object? Question options: x = Fruit() x = Fruit(Apple) x = Apple() x = Apple(McIntosh) Question
Question 1
Which statement successfully creates a new Apple object?
Question options:
x = Fruit()
x = Fruit("Apple")
x = Apple()
x = Apple("McIntosh")
Question 2
Given the code snippet below, what methods does an object of the Rectangle class have? class GeometricShape :
def __init__(self, x, y) : self._x = x
self._y = yself._fill = None self._outline = "blue" ...
def getX(self) : return self._x
def getY(self) : return self._y
class Rectangle(GeometricShape) :def __init__(self, x, y, width, height) :
super().__init__(x, y) self._width = width self._height = height
def getWidth(self) : return self._width
def getHeight(self) : return self._height
Question options:
getWidth(), getHeight()
getX(), getY(), getWidth(), getHeight()
getX(), getY(), setColor()
getX(), getY(), getWidth(), getHeight()
Question 3
What object oriented programming concept can often be used to eliminate explicit type tests?
Question options:
Class variables
Encapsulation
Functions
Polymorphism
Question 4
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?
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]
Question 5
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 |
Question 6
Consider the following function:
1.2.3.4.5.6.What will happen if lines #2 and #3 were swapped with lines #4 and #5?
def mystery(n, if n == 0 : return 0 if n == 1 : return m
m) :# special case 1
# special case 2 return m + mystery(n - 1), m)
What will happen if lines #2 and #3 were swapped with lines #4 and #5?
Question options:
The original function and the modified function will return the same result for all integer values of n and m.
The original function and the modified function will return different results for all integer value of n and m.
The original function and the modified function will return the same result when n is greater than m, and different results when m is greater than n.
The original function and the modified function will return the same result when n is less than m, and different results when m is less than n.
Question 6
Consider the following code segment:
def f1(n) :
if n < 0 :
return 0
if n % 2 == 1 :
return n
return f2(n + 1)
def f2(n) :
if n < 0 :
return 0
if n % 2 == 0 :
return n
return f1(n // 2)
print(f2(7))
When this code is run, it will display:
Question options:
0
1
3
7
The following function is supposed to use recursion to compute the area of a square from the length of its sides. For example, squareArea(3) should return 9.def squareArea(sideLength) :
if sideLength == 1 :
return 1
else :
____________________
What line of code should be placed in the blank to achieve this goal?
Question options:
return squareArea(sideLength - 1)
return 2 * squareArea(sideLength - 1)
return 2 * sideLength + squareArea(sideLength - 1)
return 2 * (sideLength 1 squareArea(sideLength - 1)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
