DOC PREVIEW
UB CSE 115 - exam 1 solved

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 – VERSION 1 Fall 2016 1 EXAMINATION INSTRUCTIONS 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, except in cases of supposed errors or ambiguities in examination questions. ► CAUTION – Candidates guilty of any of the following, or similar, dishonest practices shall be immediately dismissed from the examination and shall be liable to disciplinary action.  Making use of any books, papers or memoranda, calculators or computers, audio or visual cassette players, or other memory aid devices, other than those explicitly authorised by the examiners.  Speaking or communicating with other candidates.  Purposely exposing written papers to the view of other candidates. The plea 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 /100Unit Exam #1 CSE115 Introduction to Computer Science I – VERSION 1 Fall 2016 2 Question 1 [10 points, 2 points each] The code given below is correct: it compiles without errors. I have added some extra spacing to make this question easier to answer. 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. fully qualified name 3. parameter declaration 4. expression 5. scope of instance variable declaration 6. assignment statement package exam1; public class Store { private institution.financial.Bank _money; public Store( institution.financial.Bank m ) { _money = m ; } } 1 5 6Unit Exam #1 CSE115 Introduction to Computer Science I – VERSION 1 Fall 2016 3 Question 2 [10 points, 2 points each] For each of the following questions, select the BEST answer from the available choices. [2 POI NTS] Fr om whi ch ar ea of me mor y does ‘ new’ all ocat e space? a) secondary st orage b) heap c) st atic regi on d) runti me st ack [2 POI NTS] What i s the val ue of a ‘ new’ expr essi on, such as new exampl e1. Bar nYard() ? a) a reference b) an i nst ance c) a vari abl e d) an obj ect [2 POI NTS] Wher e i n memory are l ocal vari abl es stored? a) secondary st orage b) heap c) st atic regi on d) runti me st ack [2 POI NTS] Whi ch answer best expl ai ns the eff ect of carryi ng out the assi gnment x = y where x and y ar e bot h vari abl es of type exampl e1. Pi g? a) x and y hol d ref erences to the same exampl e1. Pi g obj ect b) x and y hol d ref erences to different exampl e1. Pi g obj ects c) x and y are t he same exampl e1. Pi g obj ect d) x hol ds a ref erence t o y, and y hol ds a ref erence t o an exampl e1. Pi g obj ect [2 POI NTS] Wher e i n memory are met hod i nvocati on recor ds st ored? a) secondary st orage b) heap c) st atic regi on d) runti me st ackUnit Exam #1 CSE115 Introduction to Computer Science I – VERSION 1 Fall 2016 4 Question 3 [10 points, 2 points each] The code sample given below is correct: it compiles without errors. package exam1; public class Zoo { public Zoo() { Habitat jungle; jungle = new Habitat(); Tiger tigger; tigger = new Tiger(); Lion nala; nala = new Lion(); jungle.addTiger(new Tiger()); jungle.addTiger(tigger); } } ANSWER THE QUESTIONS BELOW: a) How many variables are declared in the code shown above? [2 points] Two variables are declared. Explanation: “Habitat jungle;” is one variable declaration “Tiger tigger;”is the second. For questions (b) through (e) assume that the class exam1.Zoo is instantiated once. b) How many Habitat objects are created? [2 points] Just one: there is only one “new Habitat()”expression. c) How many Tiger objects are created? [2 points] Two, since there are two “new Tiger()”expressions. d) How many Lion objects are created? [2 points] Just one: there is only one “new Lion()”expression. e) How many Zoo objects are created? [2 points] Just one: see hereUnit Exam #1 CSE115 Introduction to Computer Science I – VERSION 1 Fall 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] Draw an object diagram which corresponds to the following memory diagram. 234 235 18952 236 18956 237 238 18959 239 18956 240 241 18952 18953 18954 18955 18956 18957 18958 18959 Assume that the variable r has location 235, s has location 236, t has location 238 and u has location 239. Also assume that r is of type Dog, s is of type Cat, t is of type Rabbit and u is of type Cat. Draw an object diagram which corresponds to the memory diagram. r s t u Dog object Cat object Rabbit objectUnit Exam #1 CSE115 Introduction to Computer Science I – VERSION 1 Fall 2016 6 Question 5 [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] In this question you must define a class. The class must be in a package whose name matches your last name. The class itself must be the same as your first name. Define two instance variables in this class, one of type State and one of type County. Assume that constructors State() and County() are


View Full Document

UB CSE 115 - exam 1 solved

Download exam 1 solved
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 solved 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 solved 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?