Assignment 10, Object-Oriented Languages
Due  November 18th, 12 noon
(To be done with your group)

  1. Write a complete (but small) program (in either C++ or Java) that demonstrates the dynamic binding of a message to method definitions (i.e., dynamic dispatch).  Explain your example. 
  2. Consider classes S and T, where S is a subclass of T.  Let's suppose T has a method m that S wants to override.  Most object-oriented languages require the argument and return types of S's overridden m method to be the same as the argument and return types of T's m method.  This requirement enables S to be a subtype of T.  Based on your understanding of how subtyping works, derive the weakest requirement that S's m method must satisfy in order for S to still be a valid subtype of T.  Illustrate your subtyping rule by giving an example that uses that rule.
  3. As we discussed in class, using inheritance for both subtyping and code reuse causes problems with encapsulation. (i) Give an example that illustrates this problem. (ii) Explain and illustrate how interfaces in Java address this problem.