Sample Data Structures Questions
Chapter 13
Linked Lists

Data Structures and Other Objects Using Java (Third Edition)
by Michael Main
ISBN 0-321-37525-4


The Purpose of These Questions

These are typical exam questions from Chapter 13 of the textbook. These exact questions might not be on your exam, but if you research and find the right answers to these questions, that should be good preparation for a real exam. (It's also possible that some of this material was not covered in your class.) At the moment there are 8 short answer questions and 10 multiple choice questions in this file.

Short Answers

    Short Answers
    Section 13.1
    Extended Classes

  1. Write one or two sentences to describe the primary advantage of implementing an extended class. Your answer should use the word "inherited" at least once.

  2. If the programmer doesn't declare any constructors for an extended class, what constructors will be inherited from the superclass? How does this inherited constructor initialize new instance variables that are not part of the superclass?

  3. Suppose that Vehicle is a class and Car is a new class that extends Vehicle. Write a description of which kind of assignments are permitted between Car and Vehicle variables.

    Short Answers
    Section 13.2
    An Ecosystem Simulation

  4. Suppose you write a new constructor for an extended class. Describe two different ways that the superclass's instance variables could be initializd within the constructor for the extended class.

  5. Suppose that v is a Vector of Objects and we write a function that expects each Object in v to be an Organism. What changes do we need to make to the function if we want it to work with a Vector of Animals instead? (Animal is extended from Organism.)

  6. In the pond life simulation program, the weeds in the pond were represented by a variable weeds with the declaration:
    Vector weeds = new Vector(MANY_WEEDS);
    The constructor for the Plant class has two arguments: the initial size of the plant (in ounces) and the growth rate of the plant (in ounces/week). Write a for-loop that will put 100 new Plants in the weeds Vector. Each Plant should have an initial size of 15 ounces, and a growth rate of 2.5 ounces/week.

Multiple Choice

    Multiple Choice
    Section 13.1
    Extended Classes
    Throughout this section,
    A is a class and B is
    a new class that extends A.
    Also, we have these variables:
    A a = new A( );
    B b= new B( );
    B b1 = new B( );
    B b2 = new B( );

  1. What Java syntax is used to declare that a class B is extended from class A?

  2. If a class B is derived from A, then which of the following terms describes A?

  3. Using the variable declarations at the top of this section, which of the following assignment statements are legal (no compilation errors)?

  4. Consider the assignment statement a=b; (with the variable declarations at the top of this section). Which answer is true?

  5. Consider the assignment statement b=(B)a; (with the variable declarations at the top of this section). Which answer is true?

  6. What is the term used to describe the situation when an extended class provides a function already provided in the superclass?

  7. Consider the declarations at the top of this section. Suppose there are two methods: f has an argument of type A and g has an argument of type B. Which statement is correct?

  8. Consider the declarations at the top of this section. Suppose there are two functions: f has an argument of type A and g has an argument of type B. Which statement is correct?



Michael Main (main@colorado.edu)