final-sample-3 - CSE 143 Sample Final Exam #3 1....

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

View Full Document Right Arrow Icon
CSE 143 Sample Final Exam #3 1. Inheritance and Polymorphism. Consider the following classes ( System.out.println has been abbreviated as S.o.pln ): public class Leo extends Don { public void method1() { S.o.pln("Leo 1"); } public void method3() { S.o.pln("Leo 3"); method1(); } } public class Mike extends Leo { public void method2() { S.o.pln("Mike 2"); super.method2(); } } public class Raph { public void method1() { S.o.pln("Raph 1"); } } public class Don extends Raph { public void method2() { method1(); S.o.pln("Don 2"); } } The following variables are defined: Raph var1 = new Don(); Leo var2 = new Mike(); Object var3 = new Raph(); Don var4 = new Leo(); In the table below, indicate in the right-hand column the output produced by the statement in the left-hand column. If the statement produces more than one line of output, indicate the line breaks with slashes as in "a / b / c" to indicate three lines of output with "a" followed by "b" followed by "c". If the statement causes an error, fill in the right-hand column with the phrase "error" to indicate this. Statement var1.method1(); var1.method2(); var1.method3(); var2.method1(); var2.method2(); var2.method3(); var3.method1(); var4.method1(); var4.method2(); var4.method3(); ((Don) var1).method2(); ((Mike) var2).method2(); ((Raph) var3).method1(); ((Don) var3).method2(); ((Leo) var4).method3(); Output ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________
Background image of page 1

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

View Full DocumentRight Arrow Icon
2. Inheritance and Comparable Programming . You have been asked to extend a pre-existing class Person that represents a person used as part of an online dating/marriage system. The Person class includes the following constructors and methods: Constructor/Method Description public Person (String name) constructs a person with the given name public String getName () returns the person's name public void engageTo (Person partner) sets the person to be engaged to the given partner public Person getFiancee () returns the person's fiancée, or null if none public boolean isSingle () returns true if the person has no fiancée public Queue<String> getPreferences () returns a queue of preferred partners public Map<String, Integer> getRankings () returns a map of rankings public String toString () returns a string representation of the person You are to define a new class called Playa that extends this class through inheritance . A Playa should behave like a Person except that it makes mischief by allowing itself to be engaged to multiple persons at the same time, keeping track of a collection of all such fiancées. You should provide the same methods as the superclass, as well as the following new behavior. Constructor/Method
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

final-sample-3 - CSE 143 Sample Final Exam #3 1....

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