To Lecture Notes

IT 212 -- May 14, 2020

Review Exercises

  1. Take this Zoom Poll Quiz. Answers marked with * are correct.
    1. In which situation is inheritance used?
      *a. To add functionality to a class without changing the class.
      b. To double the number of objects that can be instantiated from a class.
      c. To reduce the number of instance variables of a class.
      d. To reduce the number of instance methods of a class.
    2. Which test is used to check if inheritance makes sense?
      a. has-a test.    *b. is-a test      c. str test    d. substitution test
    3. What is another name for the base class?
      a. derived class   b. helper class   c. subclass   *d. parent class
    4. What is another name for the derived class?
      a. parent class   *b. subclass   c. superclass    d. utility class
    5. If the class A is defined as
      class A:
          def __init__(self, x, y):
              self.x = x
              self.y = y
      
      What is the output from these statements?
      a = A(3, 5)  #     a      b
      b = A(7, 9)  #   x  y   x  y
      a.x += 2     #  ====== ======
      b.y += 4     #   3  5   7  9
      a.y += 6     #   5 11  15 13
      b.x += 8     #
      print(a.y, b.x)# Output: 11 15
      
      a. 5 15    b. 7 15    c. 9 15    *d. 11 15
    6. Which is the base class?
      a. Motorcycle     *b. Vehicle    c. There is no inheritance relationship.
    7. Which is the base class?
      *a. CelestialObject     b. Planet    c. There is no inheritance relationship.
    8. Which is the base class?
      a. Card     b. Deck    *c. There is no inheritance relationship.
    9. What is the output?
      a = [34, 86, 22, 97, 33]
      print(a.pop(1))
      a.sort( )
      a.append(50)
      a.reverse( )
      print(a)
      
      a. [22, 33, 34, 50, 86, 97]
      *b. [50, 97, 34, 33, 22]
      c. [97, 50, 34, 33, 22]
      d. [97, 86, 34, 33, 22]
  2. Identify the inheritance relationships between these classes. Use the is-a test.
         Student   SeminarSpeaker   Professor   Person   TeachingAssistant
         Course   Employee   Seminar   Secretary   Lecture   DepartmentChair
         ComputerLab   Janitor

    Ans: Indentation means derived class
    Person
        Student
        Secretary
        SeminarSpeaker
        Janitor
        Employee
            TeachingAssistant
            Professor
                DepartmentChair
                
    Course
        Seminar
        
    Lecture
    
    ComputerLab
    

Project 3a

Inheritance Examples

Project 3b

Practice Exam