Assignment 10
Due 11/16/04 12:30 p.m.
(Must be done with your group)
- Consider the following classes. Assume all methods are virtual.
class T { void m() { ... }; void n() { ...}}
class S1 extends T { void m() { ... }}
class S2 extends T { void o() { ...}}
- [skill 19.1] Give the v-tables for T, S1, and S2 (use ASCII art)
- [skill 19.2] Consider the following code fragment:
T t;
if (cond) t = new S1(); else t = new S2();
t.m();
((T) t).m();
t.o();
For the three method invocations
indicate precisely what will happen. If the method invocation requires
a dynamic dispatch, explain the steps leading to the dynamic dispatch using
your v-tables from the previous part.
- [skill 19.3] Consider the following Java interface:
interface I { void m(); void n(); }
which doesn't inherit from any interface and has two methods
m and n. Now consider
the following code that uses the interface:
I i;
i = ... /* initialized somehow */
i.m();
Will the correct target of the call "i.m()"
always be at the same offset (0 for example) in the v-table of the object
referenced by i?
Why or why not? Explain.
- [skill 20.1] Describe what "referential transparency" means and
discuss why this is a desirable property to have in a language.
- [skill 20.1] What is a "functional form"? Write a functional
form of your choosing in MYSTERY (which supports many features traditionally
found only in functional languages!). Use
this link for
submitting your programs. Assume that MYSTERY allows assignments and
parameter passing only between equal types and uses structural type equality.
You may submit as many programs as you wish.
- [synthesis] Each instance of a class gets its own copy of instance
variables. Does each instance of a class need its own copy of its
methods and a v-table? Explain.