DOC PREVIEW
UB CSE 115 - Exam 1 Example

This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Unit%Exam%#1% CSE115%Introduction%to%Computer%Science %I% Spring%2016%%1%%!EXAMINATION%INSTRUCTIONS%%NAME:%___________________________%%PERSON%NUMBER:%___________________________%%SIGNATURE:%___________________________%%This%examination%has%6%pages.%Check%that%you%have%a%complete%paper.%Each%candidate%should%be%prepared%to%produce,%upon%request,%his%or%her%SUNY/UB%card.%This%examination%has%5%questions.%Answer%all%questions.%You$have$60$minutes$to$complete$this$examination.$$Use$your$time$accordingly.$%READ%AND%OBSERVE%THE%FOLLOWING%RULES:%%► Names%are%pre-printed%on%the%exam%booklets.%%Ensure%that%you%have%YOUR%exam.%► Sign,%using%your%usual%signature,%in%the%space%provided%on%the%back%cover.%► All%of%your%writing%must%be%handed%in.%This%booklet%must%not%be%torn%or%mutilated%in%any%way,%and%must%not%be%taken%from%the%examination%room.%► Show% all%of% your%work% in%arriving%at% an%answer,% unless%instructed%otherwise.% Partial% credit%will%be%awarded%as%appropriate.%► Candidates%are%not%permitted%to%ask%questions%of%the%invigilators,% ex cep t% in% ca ses % of% su pp os ed %errors%or%ambiguities%in%examination%questions.%► CAUTION% –% Candidates% guilty% of% any% of% the% following,% or% similar,% dishonest% practices% shall% be%imme d iat ely %d ismissed%from %th e%e x amination%and %s h all%b e %lia ble%to%disciplinary%action.%♦ Making% use% of% any% books,% papers% or% memoranda,% calculators% or% computers,% audio% or%visual% cassette% players,% or% other% memo ry% aid% d evices,% other% than% those% explicitly%authorised%by%the%examiners.%♦ Speaking%or%communicating%with%other%candidates.%♦ Purposely%exposing% w ritten%p apers% to%the%view%of%other% ca ndidates.%The%p lea% of%accident%or%forgetfulness%shall%not%be%received.%%---------------------------%DO%NOT%WRITE%BELOW%THIS%LINE!%---------------------------%%Q1%Q2%Q3%Q4%Q5%TOTAL%%$/10%/10%/10%/10%/10%/50%/100$%! !Unit%Exam%#1% CSE115%Introduction%to%Computer%Science %I% Spring%2016%%2%%Question!1![10!points,!2!points!each]!The!code!given!below!is!correct:!it!compiles!without!errors.!!Circle,!and!identify!by!number,!one!and$only$one!example!of!each!of!the!following!items!in!the!code!below.!!If!you!believe!no!example!exists,!write!“no#example”!next!to!that!item!in!the!list.!!To!show!you!how!I!want!the!question!answered,!the#first#one#is#done#for#you.!!1. access!control!modifier!2. expression!3. class!body!4. fully!qualified!name!5. argument!6. assignment!statement!!package part1;p public class Farm { private example1.BarnYard _yard; public Farm() { _yard = new example1.BarnYard(); } public void addOneMovingChicken() { example1.Chicken c = new example1.Chicken(); _yard.addChicken(c); c.start(); } public void addOneMovingPig() { example1.Pig p = new example1.Pig(); _yard.addPig(p); p.start(); } public void addOneMovingButterfly() { example1.Butterfly b = new example1.Butterfly(); _yard.addButterfly(b); b.start(); } }! !1$Unit%Exam%#1% CSE115%Introduction%to%Computer%Science %I% Spring%2016%%3%%Question!2![10!points,!2!points!each]!For!each!of!the!following!questions,!select!t he!BEST!answer!from!the!available!choices.!!! [2 POINTS] Where in memory are method invocation records stored? a) secondary storage b) heap c) static region d) runtime stack [2 POINTS] Where in memory are static variables stored? a) secondary storage b) heap c) static region d) runtime stack [2 POINTS] From which area of memory does ‘new’ allocate space? a) secondary storage b) heap c) static region d) runtime stack [2 POINTS] Which of the following has the same value as 11102? a) 710 b) 1410 c) 2810 d) 5610 [2 POINTS] What is the value of a ‘new’ expression, like new part2.Farm() ? a) a reference b) an instance c) a variable d) an objectUnit%Exam%#1% CSE115%Introduction%to%Computer%Science %I% Spring%2016%%4%%Question!3![10!points,!2!points!each]!The!code!sample!given!below!is!correct:!it!compiles!without!errors.!!package exam1; public class FamilyFarm { public FamilyFarm() { example1.BarnYard enclosure; enclosure = new example1.BarnYard(); example1.Chicken daisy; daisy = new example1.Chicken(); example1.Pig wilbur; wilbur = new example1.Pig(); enclosure.addChicken(new example1.Chicken()); enclosure.addPig(wilbur); } } ANSWER)THE)QUESTIONS)BELOW:)!a) How!many!variables!are!declared!in!the!code!shown!above?![2!points]!!!!For!questions)(b))through)(e))assume)that)the)class)exam1.FamilyFarm)is)instantiated)once.)!b) How!many!example1.BarnYard!objects!are!created?![2!points]!!!!c) How!many!example1.Chicken!objects!are!created?![2!points]!!!!!d) How!many!exam1.FamilyFarm!objects!are!created?![2!points]!!!!e) How!many!objects!are!added!to!BarnYard!enclosure?![2!points]!!!!!Unit%Exam%#1% CSE115%Introduction%to%Computer%Science %I% Spring%2016%%5%%!!Question!4![10!points!–!10!points!perfect,!7!points!essentially!correct!but!with!small!mistakes,!3!points!clearly!wrong!but!with!some!correct!elements,!0!points!for!anything!else]!Study!the!following!partial!class!definition!(the!omitted!parts!are!not!relevant!to!the!question).!!Complete!the!definition!of!a!parameterless!void!method!named!swap!so!that!it!interchanges!the!values!of!the!the!two!instance!variables!_a!and!_b.!!package exam; public class Question4 { private String _a; private String _b; public Question4() { // body of constructor not relevant to question } // define your swap method below: } !!!Unit%Exam%#1% CSE115%Introduction%to%Computer%Science %I% Spring%2016%%6%%Question!5![10!points]!Complete!each!of!the!following!sentences.!!Choose!the)best)answer!for!each!sentence!from!the!phrases!given!below.!!You!may!use!each!phrase!at!most!once;!not!all!phrases!will!be!used.!• A!variable!declaration!determines!a/the!______________________!and!a!name!for!a!variable.!• When!carrying!out!an!assignment!statement!a/the!______________________!on!the!right!of!the!a/the!______________________!operator!is!evaluated!first,!and!the!resulting!value!is!stored!in!a/the!______________________!on!the!left.!• When!performing!a!method!call,!the!!______________________!are!evaluated!and!the!resulting!values!are!assigned!to!the!corresponding!!______________________.!• The!‘new’!operator!allocates!memory!on!the!!______________________!to!hold!the!representation!of!an!object.!•


View Full Document

UB CSE 115 - Exam 1 Example

Download Exam 1 Example
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Exam 1 Example and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Exam 1 Example 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?