CS1026 Midterm Fall 2007

Download CS1026 Midterm Fall 2007

Post on 16-Aug-2015

217 views

Category:

Documents

3 download

DESCRIPTION

CS1026 Midterm Fall 2007

TRANSCRIPT

The University of Western OntarioDepartment of Computer ScienceComputer Science 026a Midterm ExamOctober 27, 20072 hoursPrint your name: ______________________________________________Student number: _______________________________________Instructions: Fill in our name and student number abo!e immediatel" On the Scantron #orm, #ill in our name and si$nature in the spaces pro!ided at the top" Encodeour student number in the area indicated b S%&'E(% (&M)E*" You have 2 hours to compete the e!am" %here +ill be (O extra time $i!en to #ill in the Scantron #orm at the end o# the exam" The e!am is out of a possibe ##$ mar%s &Part # is out of '$( Part 2 is out of )$*" ,art - of the e!am consists of +utipe Choice ,uestions" Circe your ans-ers on this e!am paper and fi in your ans-ers on the provided Scantron form" ,art 2 consists of ,uestions for -hich you -i provide -ritten ans-ers: Write your ans-ers in the spaces provided in this e!am paper" The mar%s for each individua ,uestion are .iven" /o- appro!imatey # minute per mar% on avera.e" There is a pa.e for rou.h -or% at the very bac% of the e!am" You may detach it if you -ish( but hand it in -ith the rest of the e!am paper"Documentation concerning the methods you may need for the classes World, Turtle, Picture, Pixel, FileChooser and Color is provided at the back of the exam.D !T T"#! T$%& P'() "!T%* D%#)CT)D T D &.,art 2 Mar.s#201)'2Tota#,art -: Multiple ChoiceChoose the best ans+er from the choices given. Choose only !) ans+er. )ach ,uestion is +orth- mark unless other+ise indicated..ou may assume that there are no syntax errors intended in any of the code provided in the ,uestions ofPart -.1. / compier -i(a) #ind sntax errors(b) fi! synta! errors(c) find o.ic errors(d) more than one of the above(e) none of the above ans-ers2. /n a.orithm shoud be -ritten(a) in 3ava(b) in machine an.ua.e(c) -ithout synta! errors(d) in a natural lan$ua$e such as En$lish(e) none of the above ans-ers3. 4n order to run a 3ava pro.ram((a) it must be compied(b) it must have a main method(c) it must have at east one other method(d) exactl t+o o# /a0, /b0, /c0(e) a of &a*( &b*( &c*4. What -i be dispayed on the screen by the foo-in. code se.ment5String word = Hello;System.out.println(word);(a) -ord(b) 1ello(c) 67eo8(d) 67eo89(e) none of the above5. 4n the previous ,uestion( println is the name of a(a) variabe(b) method(c) cass(d) ob:ect2(e) none of the above06. What -i be output by the foo-in. 3ava statement5System.out.println((double)(12/5));(a) 2"2(b) 2"$(c) 2(d) 2")(e) none of the above7. What -i be output by the foo-in. 3ava statement5System.out.println((double)12/5);(a) 2"2(b) 2"$(c) 2(d) 2")(e) none of the above8. What -i be output by the foo-in. 3ava statement5System.out.println((int)(12.0/5));(a) 2"1(b) 2"$(c) 2(d) 2")(e) none of the above9. What -i be output by the foo-in. 3ava statement5System.out.println((int)12.0/5));(a) 2"1(b) 2"$(c) 2(d) 2")(e) none of the above10.&2 mar%s* Suppose -e have definedint m = 1! n = ";The vaue of the e!pression m / n # m $ n is(a) 6"3(b) '(c) '"$(d) #$$(e) none of the above111.&2 mar%s* Suppose -e have definedint n = "; double % = 2.5;The vaue of the e!pression 5 & % ' n / 5 is(a) #2")(b) --"7(c) #"2(d) ##")(e) none of the above12.Suppose -e have definedint num1 = 50! num2 = 50;The vaue of the e!pression (num1 == num2) is(a) true(b) fase(c) )$(d) $(e) none of the above13.What -i be printed by the foo-in. statement5System.out.println(%((y);(a) !;;y(b) x4(c) !y(d) this statement -i not compie(e) none of the above ans-ers14.&2 mar%s* What -i be the vaue of ! after the foo-in. code se.ment is e!ecuted5int % = ); % = % # %; % = % # %;(a) 0(b) '(c) !acty t-o of &a*( &b*( &c*(e) ?one of the above ans-ers19.The identifier num in the above code is a(a) reference variabe(b) !ariable o# primiti!e tpe(c) constant(d) name of a method(e) none of the above20.The identifier S234 in the above code is a(a) reference variabe(b) variabe of primitive type(c) constant(d) name of a method(e) none of the above221.The identifier w1 in the above code is a(a) re#erence !ariable(b) variabe of primitive type(c) constant(d) name of a method(e) none of the above22.Which of the foo-in. statements is=are true about the %ey-ord new in the above code5 (a) 4t refers to the current ob:ect"(b) 4t is the name of a method"(c) 4t is the name of a variabe"(d) 4t creates a ne- ob:ect"(e) More than one o# the abo!e statements are true"23.Which of the foo-in. in the above code is=are parameters to methods5(a) num(b) -#(c) t#(d) exactl t+o o# /a0, /b0, and /c0(e) a of &a*( &b*( and &c*24.Which of the foo-in. in the above code is=are ob:ect methods5(a) Word(b) Turte(c) #or+ard(d) e!acty t-o of &a*( &b*( and &c*(e) a of &a*( &b*( and &c*25.Suppose -e have an array decared byint /0 int:rr = -2!"!;!!109;What vaue is stored in int:rr/10 5(a) #(b) 2(c) 2(d) $(e) none of the above26.7o- can -e refer to the ast eement in the array of the previous ,uestion5(a) int/rr@#$A(b) int/rr@int/rr"en.thA(c) int9rr:int9rr"len$th ; - . ?= -2> .@@0 int9rr2:.< = -00>(c) for &int % C #9 % DC ##9 %EE* int/rr2@%A C #$$9(d) for &int % C $9 % DC ##9 %EE* int/rr2@%A C #$$9(e) none of the above28.4n the previous ,uestion( int:rr2 is a(a) re#erence !ariable(b) variabe of primitive type(c) constant(d) name of a method(e) none of the aboveConsider the #ollo+in$ code se$ment" &se it to ans+er the next 2 7uestions"int n1! n2 = 0;double % = 12.)";String test;6orld w1 = new 6orld();7urtle t1 = new 7urtle(w1);7urtle t2 = t1;29. 7o- many variabes are decared in this code se.ment5 (a) $(b) )(c) '(d) 7(e) none of the above30.7o- many ob:ects are created in this code se.ment5(a) $(b) #(c) 2(d) A

Recommended

View more >