{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

Info icon This preview shows pages 1–4. 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
Image of page 1

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

View Full Document Right 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
Image of page 2
CS61B, Midterm #1, Fall 1998 (8 points) This question refers to the DList class used in Homework 4. It is a doubly-linked, cyclic list class with a
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern