{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# q4soln - cs 302 Fall 2006 Quiz 4(1019mm Solution Answers...

This preview shows pages 1–2. Sign up to view the full content.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cs 302 Fall 2006 Quiz 4 (1019mm) Solution Answers must be hand-written. Show all your work on the quiz. Question 1 [4 points] Consider the following complete class deﬁnition: public class Info { private static int aa = 4; private int bb = 8; public static int cc = 3; public final int dd = 7; public Info(int a, int b) { aa = a; bb = b; } public static void methodl() { // LINE_A l public void method2() { System.out.println("methodZ"); } private static void method3() { System.out.println("methodB"); } private void method4() { // L::NE_B } } Consider inserting a line of code at the places marked LINE_A and LINE_B (i.e., replace the entire comment with the line of code). For each of the following lines of code, where could the code be inserted so that the class would compile without error? Your answer choices are: "Line_,A only", " " " "neither line". Choices may be used zero or more "Line_B only, Line4A and Line_B, times. Code to insert Answer .1 La methodZ ( ) ; Line__B only Lb aa = 3; Line_A and Line_B 1x Method3(); neither line (note the capital "M"; if the code had been "method3 ( ) ; " then the answer would be "Line_A and Line_BU 141 bb = dd + cc; Line_B only Continues on back Question 2 [3 points] Complete the countInRange method. This method takes a 2—dimensional array of ints and an upper and lower bound and returns the number of ints in the array between upper and lower (inclusive). Note that you may not assume that the 2-d array is rectangular. public static int countlnRange<int arr, int upper, int lower) { int count = O; for (int row = 0; row < arr.length; row++) for (int col = 0; col < arr[row].length; col++) if (arr[row][col] >= lower && arr[row][col] <= upper) count++; return count; Question 3 [3 points] Suppose the class Test has been deﬁned as follows: class Test { C:O&Q,'TVQGL private int x, y; public Test<int a, int b) { x a; yb; } public int methodl(int n) { x = 3 * n; n=x+y; return n; } public void method2(int x) { Fﬁéfbwdl x 2 * x; y x; W\ Efll } , public void print() { ' System.out.println("1nside: x = " + x + ", y = " + y); rookadQ. H x— What is the output for the following lines of code? H H Test test = new Test(l, 2); int x = 3, y = 4; y = test.methodl(x); test.print(); test.method2(x); test.print(); System.out.println("0utside: X = " + X + ", y = " + y); Answer: Inside: x = 9, y — 2 Inside: x = 9 y = 6 I Outside: X = 3, y = 11 ...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

q4soln - cs 302 Fall 2006 Quiz 4(1019mm Solution Answers...

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

View Full Document
Ask a homework question - tutors are online