hw8 - (vi) E inherits from C (vii) E inherits from B (viii)...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Suggested Homework #8 Suggested Homework #8 (for Quiz #8 on 11/30/06) Consider the Java code below: interface A { void m(A y); } interface C extends A { A n(C y); } class B implements A { int x; void m(A y){ return; } } class D extends B { int y; } class E extends B implements C { A n(C z){ return z; } } (a) Name the types, classes, and interfaces that have been created. (b) Using the notion of structural subtyping which of the following is true ? (i) A <: B (ii) A <: C (iii) B <: A (iv) D <: C (v) D <: B (vi) E <: C (vii) E <: B http://www.cs.ucsd.edu/classes/fa06/cse130/shw/shw8.html (1 of 3) [2/13/2008 5:26:47 PM]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Suggested Homework #8 (viii) E <: A (c) Which of the following is true ? (i) A inherits from B (ii) A inherits from C (iii) B inherits from A (iv) D inherits from C (v) D inherits from B
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (vi) E inherits from C (vii) E inherits from B (viii) E inherits from A (d) Which of the following methods typecheck ? (i) void fa(A x){ x.m(x); }; (ii) void fb(B x){ x.n(x); }; (iii) void fc(C x){ x.n(x); }; (e) Suppose that there were methods fa,fb,fc with the signatures shown in part (d). Which of the following pieces of code typecheck ? Explain. (i) A a = A(); fa(a); (ii) B b = B(); fa(b); (iii) B b = B(); fc(b); http://www.cs.ucsd.edu/classes/fa06/cse130/shw/shw8.html (2 of 3) [2/13/2008 5:26:47 PM] Suggested Homework #8 (iv) D d = D(); fa(d); (v) D d = D(); fa(d); fb(d); fc(d); (vi) E e = E(); fa(e); fb(e); fc(e); http://www.cs.ucsd.edu/classes/fa06/cse130/shw/shw8.html (3 of 3) [2/13/2008 5:26:47 PM]...
View Full Document

This homework help was uploaded on 02/14/2008 for the course CSE 130 taught by Professor Jhala during the Fall '06 term at UCSD.

Page1 / 3

hw8 - (vi) E inherits from C (vii) E inherits from B (viii)...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online