Preview

15 - General OOP #1

 1. A class is a particular instance of an object

  FALSE

  TRUE

 2. Objects have attributes (e.g. run, jump) and methods (e.g. a person's name, age etc.)

  TRUE

  FALSE

 3. In the code below, 'self' is what is referred to as the Class Name.
class Address():
    """ Hold all the fields for a mailing address. """
    def __init__(self):
        """ Set up the address fields. """
        self.name = ""
        self.line1 = ""
        self.line2 = ""
        self.city = ""
        self.state = ""
        self.zip = ""

  TRUE

  FALSE

 4. The def __init__(self) is special function called a constructor in other languages. It has to be called and will not run automatically when the class is created.

  TRUE

  FALSE

 5. The self. is kind of like the pronoun _________. When inside the class Address we are talking about my name, my city, etc

  call

  you

  never

  my

 6. The class code defines a class and it actually automatically aldo creates an instance of one (e.g. an object)

  FALSE

  TRUE

 7. In what line is an instance of the Class 'Address' being created?
class Address():
    """ Hold all the fields for a mailing address. """
    def __init__(self):
        """ Set up the address fields. """
        self.name = ""
        self.line1 = ""
        self.line2 = ""
        self.city = ""
        self.state = ""
        self.zip = ""

# Create an address
home_address = Address()
 
# Set the fields in the address
home_address.name = "John Smith"
home_address.line1 = "701 N. C Street"
home_address.line2 = "Carver Science Building"
home_address.city = "Indianola"
home_address.state = "IA"
home_address.zip = "50125"

  self.name = ""

  home_address.name = "John Smith"

  def __init__(self):

  home_address = Address()

 8. To better visualize classes and how they relate, programmers often use code (e.g. the source code of the application itself)

  FALSE

  TRUE

 9. It is possible to create a class and inherit all of the attributes and methods of a parent class.

  FALSE

  TRUE

 10. In the following example, Employee is a parent class to Customer and Person.
class Person():
    def __init__(self):
        self.name = ""
 
class Employee(Person):
    def __init__(self):
        # Call the parent/super class constructor first
        super().__init__()
 
        # Now set up our variables
        self.job_title = ""
 
class Customer(Person):
    def __init__(self):
        super().__init__()
        self.email = ""
 
john_smith = Person()
john_smith.name = "John Smith"
 
jane_employee = Employee()
jane_employee.name = "Jane Employee"
jane_employee.job_title = "Web Developer"
 
bob_customer = Customer()
bob_customer.name = "Bob Customer"
bob_customer.email = "[email protected]"

  FALSE

  TRUE