Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Pre-quiz 3-Fall 2007

1. Who is your grading TA?

2. What is the difference between a Stack and a Queue? Give an example where you would use each one.

3. Consider the following code
public abstract class Animal {

  public abstract String speak();
  public String toString() { return "An animal";}
  public String favoriteFood() { return "Anything"; }
  public void eat() { System.out.println("Tasty!"); }

}

public class Dinosaur extends Animal {

  public static int NUM_DINOSAURS = 0;

  public Dinosaur(){
    super();
    NUM_DINOSAURS = NUM_DINOSAURS + 1;
  }

  public static boolean isExtinct() { return (NUM_DINOSAURS == 0); }
  public void remove() { NUM_DINOSAURS = NUM_DINOSAURS - 1; }
  public String speak() { return "ROAR!"; }
  public String favoriteFood() { return "Plants"; }
}


(a) Which of the following declarations are valid? Check all that apply.
(i) Animal littleFoot = new Dinosaur();
(ii) Dinosaur littleFoot = new Dinosaur();
(iii) Animal fido = new Animal();
(iv) Dinosaur fido = new Animal();

(b) Given a Dinosaur petrie = new Dinosaur(), what do the following commands return when typed in the Dr. Java interactions pane?
(i) petrie.toString()
(ii) Dinosaur.isExtinct()
(iii) petrie.speak()
(iv) petrie.favoriteFood()

(c) Given a Animal cera = new Dinosaur(), do the following lines compile?
(i) cera.speak();
(ii) cera.remove();
(iii) cera.eat();


Ask questions on Pre-Quiz 3-Fall 2007 Questions

Link to this Page