Midterm 1, CSCI 5535
October 2nd, 2002

You have 50 minutes to answer these questions.  Please read all questions before you start.

  1. [25 points]  Many object-oriented languages use an invariant type system in order to get subclassing and subtyping with the same mechanism (inheritance)
    1. What is an invariant type system
    2. Give an example that illustrates a limitation of invariant type systems. 
    3. Describe a type-safe alternative of invariant type systems that address the limitations in your example.
  2. [25 points] Snyder notes that using inheritance for both code reuse and subtyping can break encapsulation. 
    1. Illustrate this using an example
    2. Rewrite your example using Java interfaces in a way that alleviates the problem
  3. [25 points] There are two kinds of "true" polymorphism: parametric and inclusion
    1. Give an example of parametric polymorphism and say why it is an example of parametric polymorphism
    2. Give an example of inclusion polymorphism and say why it is an example of inclusion polymorphism
  4. [25 points] Imagine a class S that (multiple) inherits from T and U.   When casting from S to T, does the compiler always know the delta with which to adjust the pointer
    1. When using non-virtual inheritance
    2. When using virtual inheritance

    Explain your answers.