prelim2fall2006ans

prelim2fall2006ans - CS 100J Prelim 2 Fall 2006 Answers...

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

View Full Document Right Arrow Icon
CS 100J Prelim 2 Fall 2006 Answers Question 1. (a) Local variable: A variable declared in the body of a method. It is created when the frame for a call is created, before execution of the method body. (b) // Store in c the number of positions k in Strings s1 // and s2 such that s1[k] == s2[k] int n= Math.min(s1.length(), s2.length()); int c= 0; // invariant: c = no. of positions i in s1[0. .k-1] and s2[0. .k-1] such that s1[i] == s2[i] for ( int k= 0; k < n; k= k+1) { if (s1.charAt(k) == s2.charAt(k)) c= c+1; } // c = no. of positions i in s1[0. .n-1] and s2[0. .n-1] // such that s1[i] == s2[i] Question 2. (a) c.Bigger(a) : true , (b) a.getJob(): ERROR. Apparent class is Student. (c) c.getJob(): “work-study”, (d) d.getJob(): “Cabbie”, (e) c.getSound(): “I'm new here.”, (f) d.getSound(): “”, (g) ((Frosh)a).getSound(): “I'm new here.”, (h) ((Frosh)d).getSound(): ERROR, (i) ((Senior)d).getSound(): “”, (j) ((Senior)a).getSound(): ERROR. Question 3
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Ask a homework question - tutors are online