IT 117: Intermediate Scripting
Quiz 6 Answers

  1. To create a new kind of object, what must you define?
    a class
  2. What do you call the special method that is used to create an object?
    constructor
  3. In Python what must the special method used to create an object be named?
    __init__
  4. What do you call an object that is created from a class?
    an instance
  5. Every method in a class must take a certain parameter. What is this parameter?
    self
  6. What two kinds of things do you define inside a class?
    variables and methods
  7. If I were writing a method in a class and wanted to set the value of the variable inside the class named count to zero, what Python statement would I write?
    self.count = 0
  8. If I had a variable named loan_1 that pointed to an object which contained the variable principle and I wanted to set the value of this variable to 1000, what Python statement would I write?
    loan_1.principle = 1000
  9. Do constructors have a return statement?
    no
  10. Write a constructor method for the class Car that sets the following attributes
    def __init__(self, manufacturer, model, year, color):
              self.manufacturer = manufacturer
              self.model       = model
              self.year        = year
              self.color       = color