Computer Science 61B - Fall 1998 - Shewchuk - Midterm 1

Computer Science 61B - Fall 1998 - Shewchuk - Midterm 1 -...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS61B, Midterm #1, Fall 1998 CS61b, Fall 1998 Midterm #1 Professor J. Shewchuk and K. Yelick Problem #1 (8 points) Consider the following class definitions. interface Cute { public int cuteness(); } class Fuzzy { public int fuzziness; public int cuteness() { return 0; } } class Puppy extends Fuzzy implements Cute { public Puppy(int i) { fuzziness = i; } public int cuteness() { return fuzziness + 1; } } For each of the four possible Main classes below, write CE, RT, or OK in the first box to the right of the code, where each of these has the meaning given below. In the second box, write the line number at which an error occurs (for CE or RT) or the value printed by the method (for OK). CE if the class will cause a compiler error when you run javac, RT if the class will compile without errors, but will cause a run-time error, OK if the class will compile and run without errors. a. public class Main { public static void main(String[] argv) { Fuzzy f; // 1 --------------------- Puppy p; // 2 | | | f = new Fuzzy(); // 3 | | | p = (Puppy) f; // 4 | | | System.out.println(p.cuteness()); // 5 --------------------- } } b. public class Main { file:///C|/Documents%20and%20Settings/Jason%20Raft. ..20Fall%201998%20-%20Shewchuk%20-%20Midterm%201.htm (1 of 7)1/27/2007 6:31:31 PM
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS61B, Midterm #1, Fall 1998 public static void main(String[] argv) { Fuzzy f; // 1 --------------------- Puppy p; // 2 | | | p = new Puppy(3); // 3 | | | f = p; // 4 | | | p = (Puppy) f; // 5 --------------------- System.out.println(p.cuteness()); // 6 } } c. public class Main { public static void main(String[] argv) { Cute c; // 1 --------------------- Fuzzy f; // 2 | | | Puppy p; // 3 | | | p = new Puppy(3); // 4 | | | f = (Fuzzy) p; // 5 --------------------- c = f; // 6 System.out.println(p.cuteness()); // 7 } } d. public class Main { public static void main(Strig[] argv) { Cute c; // 1 --------------------- Fuzzy f; // 2 | | | f = new Puppy(3); // 3 | | | c = (Cute) f; // 4 | | | System.out.println(p.cuteness()); // 5 --------------------- } } Problem #2 file:///C|/Documents%20and%20Settings/Jason%20Raft. ..20Fall%201998%20-%20Shewchuk%20-%20Midterm%201.htm (2 of 7)1/27/2007 6:31:31 PM
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

Computer Science 61B - Fall 1998 - Shewchuk - Midterm 1 -...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online