final-sample-1 - CSE 143 Sample Final Exam #1 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 #1 1. Inheritance and Polymorphism . Consider the following classes ( System.out.println has been abbreviated as S.o.pln ): public class Cup extends Box { public void method1() { S.o.pln("Cup 1"); } public void method2() { S.o.pln("Cup 2"); super.method2(); } } public class Pill { public void method2() { S.o.pln("Pill 2"); } } public class Jar extends Box { public void method1() { S.o.pln("Jar 1"); } public void method2() { S.o.pln("Jar 2"); } } public class Box extends Pill { public void method2() { S.o.pln("Box 2"); } public void method3() { method2(); S.o.pln("Box 3"); } } The following variables are defined: Box var1 = new Box(); Pill var2 = new Jar(); Box var3 = new Cup(); Box var4 = new Jar(); Object var5 = new Box(); Pill var6 = new Pill(); 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(); ((Cup) var1).method1(); ((Jar) var2).method1(); ((Cup) var3).method1(); ((Cup) var4).method1(); ((Jar) var4).method2(); ((Box) var5).method2(); ((Pill) var5).method3(); ((Jar) var2).method3(); ((Cup) var3).method3(); ((Cup) var5).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 Point that represents 2-D (x, y) coordinates. The Point class includes the following constructors and methods: Constructor/Method Description public Point() constructs the point (0, 0) public Point(int x, int y) constructs a point with the given x/y coordinates public void setLocation(int x, int y) sets the coordinates to the given values public int getX() returns the x-coordinate public int getY() returns the y-coordinate public String toString() returns a
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.

This document was uploaded on 12/17/2011.

Page1 / 7

final-sample-1 - CSE 143 Sample Final Exam #1 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