-
Class Definition
Which of the following is a good and valid definition for a class representing a car?
-
Class Instance
Using the class definition below, which line creates a new Car object with 4 wheels and 2 doors?
class Car(object):def __init__(self, w, d):self.wheels = wself.doors = dself.color = "" -
Methods
Which of the following methods changes the color of the car, based on the definition below?
class Car(object):def __init__(self, w, d):self.wheels = wself.doors = dself.color = "" -
Method Call
You create a car with
mycar = Car(4, 2). Which is a line of code to change the color of mycar to "red"?class Car(object):def __init__(self, w, d):self.wheels = wself.doors = dself.color = ""def paint(self, c):self.color = c -
Special Methods
With the code below, what does the line
print(mycar == yourcar)print?class Car(object):def __init__(self, w, d):self.wheels = wself.doors = dself.color = ""def paint(self, c):self.color = cdef __eq__(self, other):if self.wheels == other.wheels and \self.color == other.color and \self.doors == other.doors:return Trueelse:return Falsemycar = Car(4, 2)mycar.paint("red")yourcar = Car(4,2)print(mycar == yourcar)
