In-Class Questions and Video Solutions

Lecture 8

  1. Class Definition

    Which of the following is a good and valid definition for a class representing a car?

     `def class Car(object):`  close
     `class Car(object):`  check
     `def Car(object):`  close
     `class A(object)`  close
    Check Show Solution

  2. Class Instance

    Using the class definition below, which line creates a new Car object with 4 wheels and 2 doors?

    class Car(object):

     `Car(mycar, 4, 2)`  close
     `mycar = Car(4, 2, "white")`  close
     `mycar = Car(4, 2)`  check
     `mycar = Car(2, 4)`  close
    Check Show Solution

  3. Methods

    Which of the following methods changes the color of the car, based on the definition below?

    class Car(object):

      ``` def paint(c): ```   close
     ``` def paint(self, c): ```   close
     ``` def paint(c): ```   close
     ``` def paint(self, c): ```   check
    Check Show Solution

  4. 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):

     Car.paint("red")  close
     mycar.paint(red)  close
     mycar.paint("red")  check
     mycar.paint(Car, "red")  close
    Check Show Solution

  5. Special Methods

    With the code below, what does the line print(mycar == yourcar) print?

    class Car(object):

     True  close
     False  check
     An error  close
    Check Show Solution

Course Info

Learning Resource Types

assignment Problem Sets
notes Lecture Notes
theaters Lecture Videos
assignment_turned_in Programming Assignments with Examples