
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

CS 100J Prelim 2 Spring 2006 Answers Question 0. (answer omitted) Question 1. (a) All parameters and local variables are created when the frame for the call is drawn, before execution of the method body. (b) y= y + (h โ 1) + 101; (c) 1. How does it start? (How do you truthify the invariant?) 2. When can it stop? 3. How does the repetend make progress toward ter- mination? 4. How does the repetend maintain the invariant? Question 2. true, Error, 20, 30, โmeowโ, โโ , โmeowโ, Error, โโ, Error. Question 3. /** = ob is a non-null dog with the same fields as this Dog / public boolean equals(Object ob) { if (ob == null ) return false ; if (!(ob instanceof Dog)) return false ; Dog dob= (Dog) ob; return getName().equals(dob.getName()) && getAge() == dob.getAge() && breed.equals(dob.breed); } /* Constructor: a Dog that is a terrier, has name Spot, and is y years old / public Dog( int y) { super ("Spot", y); breed= "terrier"; } Question 4. /* Remove all CATs from v and return a Vector that contains the removed CATs / public static Vector