Final.fa08

# Final.fa08 - Signature cs11f Name Student ID CSE 11 Final...

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

Signature _____________________ Name ________________________ cs11f ____ Student ID ____________________ CSE 11 Final Fall 2008 Page 1 ___________ (20 points) Page 2 ___________ (10 points) Page 3 ___________ (16 points) Page 4 ___________ (28 points) Page 5 ___________ (7 points) Page 6 ___________ (26 points) Page 7 ___________ (16 points) Page 8 ___________ (13 points) Page 9 ___________ (10 points) Total ___________ (146 points = 140 base points + 6 points EC [5%]) (100%)

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

View Full Document
1 (Partial) Operator Precedence Table Operators Associativity * / % left to right + - left to right < <= > >= left to right == != left to right && left to right || left to right = right to left 1) Which of the following are not valid Java identifiers? (Circle your answer(s).) thirdLine 3rdLine line3 extends S.E. South East _SE_ Public 2) Using the operator precedence table above, evaluate each expression and state what gets printed. Remember short-circuit evaluation with && and ||. int i = 1, j = 2, k = 3, m = 2; System.out.println( j >= i && k == m ); ________ System.out.println( i >= 1 || j < 4 ); ________ System.out.println( !( k > m ) ); ________ System.out.println( !((i > 4) || (j <= 6)) == ((i <= 4) && (j > 6)) ); _________ 3) What gets printed? int a = 2, b = 7; System.out.println( -1 + ++a * 5 + 17 % 5 ); _________ System.out.println( 6 + b++ - 5 / 9 + 4 ); _________ 4) What gets printed? public class Question4 { public static void main( String[] args ) { final int MAX = 6; int i = -2, j = -3; for (i = 4; i < MAX; ++i ) { j = 5; while ( j <= MAX ) { System.out.println( i + " " + j ); ++j; } } System.out.println( i + " " + j ); } }
2 5) What gets printed as a result of the call F5( 3, -1 ) ? __________ public void F5( int a, int b ) { if ( (a > 0) && (b > 0) ) { if ( a > b ) { System.out.println( "A" ); } else { System.out.println( "B" ); } } else if ( (a < 0) || (b < 0) ) { System.out.println( "C" ); } else { System.out.println( "D" ); } } Give an example of values passed as arguments to F5() that would result in the method printing "D". F5( _____ , _____ ); 6) What value is returned as a result of the call a(6) to the method below? ________ public int a( int x ) { int local; if ( --x > 0 ) { local = a( x - 1 ) + x; return local; } else { return 0; } } Which of the following rewrites of this method are the same as the one above? A B C or All of them Circle your answer at the end of the line above. public int a( int x ) { if ( --x > 0 ) return a( x - 1 ) + x; else return 0; } public int a( int x ) { int local = 0; if ( --x > 0 ) local = a( x - 1 ) + x; return local; } public int a( int x ) { if ( --x > 0 ) return a( x - 1 ) + x; return 0; } A B C

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

View Full Document
3 7) A bear is an animal and a zoo contains many animals, including bears. Three classes Animal, Bear, and Zoo are declared to represent animal, bear, and zoo objects. Which of the following is the most appropriate set of declarations? ________ A B class Animal extends Bear { ... } class Bear extends Animal { ... } class Zoo { class Zoo { private Animal[] zooAnimals; private Animal[] zooAnimals; } } C D class Animal extends Zoo { class Bear extends Animal, Zoo { ... } private Bear zooBear; } E F class Zoo extends Animal { class Bear extends Animal implements Zoo { ... } private Bear[] zooAnimals; } 8) An interface definition is limited to having only ______________________________ and ________________________________.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern