CS 5535: Homework 3
Due date: October 8th, 1999 at 5:00 p.m.
Please submit your solution on paper.
-
One of the points in [Snyder86] is that instance variables of a class should
not all be visible to its subclasses (i.e., not "child accesses all").
Give two examples, one in Modula-3 and one in Java of classes where this
is enforced (i.e., the child cannot access all the instance variables of
its superclass). (10 points per example. Total: 20)
-
[Snyder86] distinguishes two kinds of inheritance: inheritance for subtypes
and inheritance for reuse. Indicate which category the following
languages fall into: (a) Smalltalk (b) Java (c) Modula-3. If a language
does not cleanly fit into a single category, indicate that. (5 points
per language. Total: 15)
-
Consider the following class hierarchy in a single inheritance language.
Assume all methods are virtual: (total points: 20)
class T { f() {...}
g() {...}
};
class S:
public T {g() {...} }
Answer the following questions:
(a) Give the virtual function table for each of the two classes.
(10 points)
(b) Give the steps involved in invoking the "g" method on a
variable "o" declared to point to S (i.e., S *o) (10 points)
-
In a multiple inheritance language (such as C++) we noted in class (and
in the Stroustrup paper) that one needs to put "deltas" in the virtual
function table along with pointers to functions. Explain why the
"deltas" are needed in the virtual function table. Illustrate with
an example. (20 points)