Midterm 1, CSCI 5535
October 2nd, 2002
You have 50 minutes to answer these questions. Please read all
questions before you start.
- [25 points] Many object-oriented languages use an
invariant type system in order to get subclassing and subtyping with the same
mechanism (inheritance)
- What is an invariant type system?
- Give an example that
illustrates a limitation of invariant type systems.
- Describe a type-safe alternative of invariant type systems that address the limitations in your
example.
- [25 points] Snyder notes that using inheritance for both code
reuse and subtyping can break encapsulation.
- Illustrate this using an example
- Rewrite your example using Java interfaces in a way that alleviates the
problem
- [25 points] There are two kinds of "true" polymorphism: parametric
and inclusion
- Give an example of parametric polymorphism and say why it is an example of
parametric polymorphism
- Give an example of inclusion polymorphism and say why it is an example of
inclusion polymorphism
- [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
- When using non-virtual inheritance
- When using virtual inheritance
Explain your answers.