MidTerm1S09Sol - 1/5 EE 322C Spring 2009 First Mid-Term Dr...

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

View Full Document Right Arrow Icon
1/5 EE 322C Spring 2009 First Mid-Term Dr. Ramesh Yerraballi You may use the back of the sheets from scratch work. Full Name : Quiz Duration : 75 minutes 1. [ 20 points ] Answer the following i. [ 8 points ] Given the following method: 1: public static int what() 2: { 3: int ret = 0; 4: for (int i = 0; i < 10; i++) { 5: if (i % 2 == 0) continue; 6: if (i == 8) break; 7: ret += i; 8: } 9: return ret; 10:} a. What does the method return? b. What does the method return if lines 5 and 6 are swapped? ii. [ 8 points ] What is output to the screen by the following code? Why? (Note: Correct answer without correct reason gets only 4 points) String str = “born”; StringPass(str); System.out.println(str); public static void StringPass(String s) { s = “touched”; } iii. [ 4 points ] If two methods in the same class have the same name, which is true? (i) They must have a different number of parameters (ii) They must have different return types (iii) They must have different parameter type lists (iv) The compiler must generate an error message _ iii __ 16 (breaks out of the loop at 8 so does not add 9) 25 (It adds all odd numbers less than 10: 1+3+5+7+9) born (str does not change after call because s is a reference which gets set to whatever str is (address is copied) and the subroutine statement s= “touched” acts on the reference and modifies it to point to a new String reference)
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/5 2. [ 20 points ] Given the following class Person and a class Driver that uses it: public class Person { static int idGen = 0; int id; String name; public Person(int i, String n) { id = ++idGen + i; name = n; } public Person(int i) { Person(i, “Doe”);
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 / 5

MidTerm1S09Sol - 1/5 EE 322C Spring 2009 First Mid-Term Dr...

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