fall06prelim1answers - Answers to Prelim 1. CS100J, Fall...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Answers to Prelim 1. CS100J, Fall 2006 David Gries djg17 1. (a) A parameter is a variable declared in the header of a method (within the parentheses). An argument is an expression that occurs in a call of a method. 1 . It’s alright if you left out the (but not …) parts. (b) 5. Line 3. Scope 4. .6. 8. Line 2. Scope 2. .18 but not 3. .6, 9. .12, 13. .16. 10. Line 9. Scope 9. .12. . 15. Line 13. Scope 13. .16. 1. (c) 1. ILLEGAL. Cast double to int not automatic. 2. d contains 3. 0 3 . b contains true 4. e contains 36.0 5. s contains “usa” 6. ILLEGAL. Can’t divide a String by an int . 2. We abbreviate “MemberOfCongress” by “MOC”. We put the types of pars within parentheses in showing a method; you didn’t have to do this. 3. (a) Senator is the subclass. (b) toString() and getName are overridden. (c) 1: 2. 2: "Member of Congress John McCain" 3: "Senator Hillary Clinton of NY" 4: ERROR. Field name is private. 5: "Senator Sen. Hillary R. Clinton"
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/01/2008 for the course CS 100 taught by Professor Fan/vanloan during the Fall '07 term at Cornell University (Engineering School).

Ask a homework question - tutors are online