final-sample-2 - CSE 143 Sample Final Exam #2 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 #2 1. Inheritance and Polymorphism . Consider the following classes ( System.out.println has been abbreviated as S.o.pln ): public class Bay extends Lake { public void method1() { S.o.pln("Bay 1"); super.method2(); } public void method2() { S.o.pln("Bay 2"); } } public class Pond { public void method2() { S.o.pln("Pond 2"); } } public class Ocean extends Bay { public void method2() { S.o.pln("Ocean 2"); } } public class Lake extends Pond { public void method3() { S.o.pln("Lake 3"); method2(); } } The following variables are defined: Lake var1 = new Ocean(); Pond var2 = new Pond(); Pond var3 = new Lake(); Object var4 = new Bay(); Lake var5 = new Bay(); Bay var6 = new Ocean(); 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.method2(); var2.method2(); var3.method2(); var4.method2(); var5.method2(); var6.method2(); var1.method3(); var2.method3(); var3.method3(); var4.method3(); var5.method3(); var6.method3(); ((Ocean) var5).method1(); ((Lake) var3).method3(); ((Lake) var4).method1(); ((Ocean) var1).method1(); ((Bay) var4).method1(); ((Lake) var2).method3(); ((Ocean) var5).method1(); ((Pond) var4).method2(); 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 Date that represents calendar dates such as March 19. The Date class includes these constructors and methods: Constructor/Method Description public Date(int month, int day) constructs a Date object with the given month/day public int getMonth() returns the month public int getDay() returns the day public void setMonth(int month) sets month to a new value public void setDay(int day) sets day to a new value public int daysInMonth(int month) returns number of days in the given month (examples: 4 30; 10 31; 2 28) public void nextDay() advances to next date, wrapping month if needed (3/19 3/20; 1/31 2/1; 12/31 1/1) public String toString() returns string version of date, such as "03/19" You are to define a new class called CalendarDate
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-2 - CSE 143 Sample Final Exam #2 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