Picture ID is REQUIRED for all exams
General Topics
- Static
- Testing
- Enumeration
- Inheritance I & II
- Polymorphism I (*NOT* Polymorphism II)
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
- Define static method and static instance variable
-
True/False — Static instance variables of a class are shared
among all objects of that class.
-
True/False — Static methods of a class can only access
static instance variables and other static methods of that class.
-
True/False — Every method of a class can access the static
data members of that class.
-
True/False — Static data members are declared and
initialized outside the class.
-
True/False — Static data members may not be final.
Testing
-
What is “white box” testing?
-
What is a unit test?
-
At what level are unit tests conducted in an OOP language?
-
What are some properties of good unit tests?
-
What are boundary conditions?
-
Give some examples of boundary conditions that you should check for when
writing unit tests.
-
What are error conditions?
-
Give some examples of error conditions that you should check for when
writing unit tests.
-
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
- Explain the concept of enumeration.
- Why would one want to create an enumerated data type?
- Give an example (no code) of an enumerated data type that one might create.
- 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;
- What does the values( ) method do relative to enumerated types?
- Write a code snippet demonstrating how the switch statement can be used
with an enumerated type.
Inheritance and Polymorphism
- Explain the differences among public, private,
and protected visibility modifiers. Be sure to mention
their role in inheritance.
- Explain how inheritance promotes code reuse.
- Explain the difference between the “uses a,” “is a,”
and “has a” relationships. Give an example of each.
- Explain how Java implements the “is a” relationship.
- Explain how Java implements the “has a” relationship.
- Describe the order in which constructors are called when using inheritance.
- Explain the difference between method overriding and method overloading.
- Define binding.
- Explain the statement: “Inheritance allows class similarities to be
shared while allowing for class differences.”
- 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?
- True/False — A base class contains all data and methods which are common to all objects
in its inheritance hierarchy.
- True/False — A derived class has direct access to its base class' private data and
methods.
- True/False — Dynamic binding is performed at run-time when the programmer uses a reference
to a base class to invoke a method.
- True/False — In Java, dynamic binding is used for all methods.
- True/False — A class labeled as final cannot be used as a base class.
- 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.
- 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.
- True/False — The protected access modifier should always be used for
instance variables of a base class that are used in a derived class.
- True/False — A class can extend more than one base class.