MidTerm1F08-sol

# MidTerm1F08-sol - 1/7 EE 322C Fall 2008 First Mid-Term Dr...

This preview shows pages 1–3. 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: 1/7 EE 322C Fall 2008 First Mid-Term Dr. Ramesh Yerraballi Full Name : Quiz Duration : 75 minutes 1. [ 20 points ] Answer the following i. [ 4 points ] In the method below, which statement about the possible output is correct? public static void what( ) { int x = 5; f( x ); // Some function whose code does not matter System.out.println( x ); } a. 0 is a possible output b. 5 is the only possible output c. Any integer can be output d. None of the above are true ii. [ 12 points ] What is the value of a, b and c after each of the following lines: [Note: The answers on one line affect the values on the next] int a = 5, b = 8, c = 0; a = b++ + c++; //Answer: a: 8 b:__ 9 __ c:_ 1 __ a = b++ + ++c; //Answer: a:_ 11 __ b:_ 10 __ c:__ 2_ a = ++b + c++; //Answer: a:_ 13 __ b:_ 11 _ c:__ 3 _ a = ++b + ++c; //Answer: a:_ 16 _ b:__ 12 _ c:__ 4 _ iii. [ 4 points ] What does the method below do? [Hint: Eliminate the wrong answers] public static int foo(String Strs) { int t = 0; for( int i=0; i < Strs.length; i++ ) t += Strs[i].length(); return t; } a. Returns the sum of the lengths of all the strings in the array of Strings passed as a parameter b. Returns the concatenation of all the strings in the array of Strings passed as a parameter c. Returns the concatenation of all the string in the array of Strings passed as a parameter, in reversed order (last string first) d. Generates a compiler error because Strs.length does not make sense 2/7 2. [ 20 points ] Given the following class X and a class useX that uses the class X : public class X { static int sta = 0; private int pri; public int pub; public X(int pr, int pu) { pri = pr; pub = pu; sta++; } public void sw() { int tmp = pub; pub = pri; pri = tmp; } public void setpr(int i) { pri = i; } public String toString() { return pub + “u:r” + pri; } } public class useX { public static void main (String args) { // The code in questions below // is assumed to be placed here } Answer the following questions independent of each other i. [ 5 points ] What is the output of the following lines of code when placed inside...
View Full Document

## This note was uploaded on 09/26/2009 for the course EE 322C taught by Professor Nettles during the Spring '08 term at University of Texas.

### Page1 / 7

MidTerm1F08-sol - 1/7 EE 322C Fall 2008 First Mid-Term Dr...

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

View Full Document
Ask a homework question - tutors are online