Computer Science 61B - Fall 1997 - Yelick - Midterm 1

Computer Science 61B - Fall 1997 - Yelick - Midterm 1 -...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: file:///C|/Documents%20and%20Settings/Jason%20Raftery/My%20Doc...nce%2061B%20-%20Fall%201997%20-%20Yelick%20-%20Midterm%201.htm CS61B, Fall 1997 Midterm #1 Professor K. Yelick Problem #1 (2 points) What is y after the following code executes? static void addOne (int x){ x += 1; } int y = 3; addOne(y); Answer: Problem #2 (8 points) Answer questions about the following classes. For parts b-e, choose one of the following: CE: The code will result in a compiler error from javac. RT: The code will compile without errors, but will cause an error of some kind run time. OK: The code will compile and run without errors. Show what the program will print. abstract class A { abstract public void foo (); } class B extends A { public void foo () { System.out.println("Calling B.foo");} protected int value = 0; } class C extends B { public void foo () { System.out.println("Calling C.foo," + value);} } class D extends C { public void foo () { System.out.println("Calling D.foo()," + value);} file:///C|/Documents%20and%20Settings/Jason%20Rafte...0-%20Fall%201997%20-%20Yelick%20-%20Midterm%201.htm (1 of 7)1/27/2007 5:40:37 PM file:///C|/Documents%20and%20Settings/Jason%20Raftery/My%20Doc...nce%2061B%20-%20Fall%201997%20-%20Yelick%20-%20Midterm%201.htm } a. (2 points) A a1 = new A(); a1.foo(); b. (2 points) A a2 = new B(); a2.foo(); c. (2 points) A a3 = new C(); a3.foo(); d. (2 points) B b4 = new D(); ((C) b4).foo(); Problem #3 (12 points) Consider the following ListNode class definition....
View Full Document

Page1 / 7

Computer Science 61B - Fall 1997 - Yelick - 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