Exam 2 Study Guide

Picture ID is REQUIRED for all exams

General Topics

Use the list of questions below as a guide when studying for Exam 2. It is by no means a comprehensive list of questions. Also, these are not the exact questions that will be on the exam. The form of the questions on the exam may also be different from those found here.

You are responsible for all material presented in lecture. You are also responsible for all material covered in lab and the concepts taught by any programming assignments.

Answering the applicable “self-test” questions in each chapter of the recommended text (by Savitch) is also a good way to review. The answers to the self-test questions are found at the end of each chapter.

Static Methods and Variables

  1. Define static method and static instance variable
  2. True/False — Static instance variables of a class are shared among all objects of that class.
  3. True/False — Static methods of a class can only access static instance variables and other static methods of that class.
  4. True/False — Every method of a class can access the static data members of that class.
  5. True/False — Static data members are declared and initialized outside the class.
  6. True/False — Static data members may not be final.

Testing

  1. What is “white box” testing?
  2. What is a unit test?
  3. At what level are unit tests conducted in an OOP language?
  4. What are some properties of good unit tests?
  5. What are boundary conditions?
  6. Give some examples of boundary conditions that you should check for when writing unit tests.
  7. What are error conditions?
  8. Give some examples of error conditions that you should check for when writing unit tests.
  9. Given the following class, what conditions you would want to test each method for?
    public class MathUtils {
        public int min(int a, int b) {
            // returns the smaller of the integers a and b
        }
        public int max(int[] items) {
            // returns the maximum integer in an array of integers
        }
        public double mean(int[] items) {
            // returns the mean (average) integer value of an array of integers
        }
        public double median(int[] items) {
            // returns the medium integer value of an array of integers
        }
    }
    

Enumeration

  1. Explain the concept of enumeration.
  2. Why would one want to create an enumerated data type?
  3. Give an example (no code) of an enumerated data type that one might create.
  4. What advantages are there to creating an enumerated type for card suits over simply using constants as shown below?
    public static final int SUIT_CLUBS = 0;
    public static final int SUIT_DIAMONDS = 1;
    public static final int SUIT_HEARTS = 2;
    public static final int SUIT_SPADES = 3;
  5. What does the values( ) method do relative to enumerated types?
  6. Write a code snippet demonstrating how the switch statement can be used with an enumerated type.

Inheritance and Polymorphism

  1. Explain the differences among public, private, and protected visibility modifiers. Be sure to mention their role in inheritance.
  2. Explain how inheritance promotes code reuse.
  3. Explain the difference between the “uses a,” “is a,” and “has a” relationships. Give an example of each.
  4. Explain how Java implements the “is a” relationship.
  5. Explain how Java implements the “has a” relationship.
  6. Describe the order in which constructors are called when using inheritance.
  7. Explain the difference between method overriding and method overloading.
  8. Define binding.
  9. Explain the statement: “Inheritance allows class similarities to be shared while allowing for class differences.”
  10. What is the base class of all classes in the Java API hierarchy? What are some of the methods in this class that it is usually advisable to override and why?
  11. True/False — A base class contains all data and methods which are common to all objects in its inheritance hierarchy.
  12. True/False — A derived class has direct access to its base class' private data and methods.
  13. True/False — Dynamic binding is performed at run-time when the programmer uses a reference to a base class to invoke a method.
  14. True/False — In Java, dynamic binding is used for all methods.
  15. True/False — A class labeled as final cannot be used as a base class.
  16. True/False — When a derived class is instantiated, its base class no-argument constructor is called whether or not an explicit call to super( ) is made.
  17. True/False — When implementing a derived class' copy constructor, its base class copy constructor is automatically called whether or not an explicit call to super( ) is made.
  18. True/False — The protected access modifier should always be used for instance variables of a base class that are used in a derived class.
  19. True/False — A class can extend more than one base class.