Expert Answers

1. (TCO 1) Which of the following would be the most appropriate choice for a method in a PhoneCharger class?
voltage
manufacturer
color
charge

2. (TCO 1) Object-oriented programming generally does not focus on _____.
A. code reuse with methods
B. information hiding
C. ease of program modifiability
D. separating the interface from the implementation
All of the above
None of the above
Only A, C, and D

3. (TCO 2) Which of the following components of a class definition have a return type?
A. Attributes
B. Accessor/mutator methods
C. Private methods
D. Public methods
A, B, and C only
B, C, and D only

4. (TCO 2) Which of the following statements is/are true?
A) A private (helper) method can only be used inside the class. It cannot be called through an object outside the class.
B. The programmer can control the scope of a data member of a class using access specifiers.
C. The state of an object should be hidden and therefore protected by unauthorized use.
All of the above
Only A and C

5. (TCO 5) Which of the following method pairs are not examples of method overloading?
A. public void rotate(); public int rotate()
B. public int move(int x, int y); public int move(int y, int x)
C. public int roll(int x, int y); public int roll(int x, int y, int z)
None of the above
Only A and B
Only A and C

6. (TCO 1) Which of the following statements is/are false?
Methods are the means by which you implement the behavior of a class.
By using the keyword class in your program, memory is allocated for the object being defined.
Objects are created during program execution and eventually destroyed.
None of the above

7. (TCO 2) You have been tasked to create an Automobile class and your boss wants you to consider the concept of encapsulation as you design your class. Which of the following actions will you take?
Declare as many class attributes public as you can, creating accessor/mutators for each one.
Package attributes and behaviors specific to an Automobile together.
Make sure to include a specific implementation for a drive method that all subclasses can inherit.
Declare the class as private.
All of the above

8. (TCO 2) You need to utilize an Item class in your own object-oriented class using composition. Luckily, one of your fellow students just finished writing their own version of an Item class. If the Item class was properly designed as a(n) _____, you do not need to know the specific details of how the class was implemented. Instead, you only need to become familiar with its _____.
abstract class; abstract methods
object-oriented instance; method implementations
black box system; interface
interface; inheritance hierarchy

9. (TCO 2) A class is designed with two public attributes: attributeOne and attributeTwo. attributeOne is an integer data type while attributeTwo is a string data type. Which pseudocode representation(s) of getters would be appropriate for this class?
A. int getAttributeOne()
{
return attributeOne
}
B. void getAttributeOne()
{
return attributeOne
}
C. int getAttributeTwo(int newAttributeTwo)
{
attributeTwo = newAttributeTwo
}
D. void getAttributeTwo()
{
return attributeTwo
}
Both A and D
None of the above

10. (TCO 4) If you have a working Bicycle class that has been thoroughly tested and you wish to add an overloaded speedUp() method that can increase the speed of a MountainBike, how should this be accomplished?
Derive a new MountainBike class from the Bicycle class.
Add the method to your existing Bicycle class.
Add the method in your project with the main method.
Make a brand new class.

11. (TCO 3) An Airplane class and a Jet class have what type of relationship?
The Jet is-an Airplane.
The Airplane is-a Jet.
The Jet has-an Airplane.
The Airplane has-a Jet.

12. (TCO 4) Why might it be better to create a derived class instead of adding a few lines of code to an existing Class?
Simplifies testing
No need to re-test the previously written class
Saves time on debugging the program

1. (TCO 4) Suppose class C is derived from class B that was in turn derived from class A. When we create an object of class C, three constructors are called: i) C, ii) B, iii) A. What is the order in which the constructors are called?
A, B, C
B, C, A
C, B, A
We cannot tell from this information.

2. (TCO 6) What is polymorphism?
An advanced form of inheritance
A single usefulness for program specificity
The ability for one interface to be associated with many implementations
Data hiding

3. (TCO 4) Which of the following is not a good example of a hierarchy that could be modeled with inheritance?
Plants
Games
Carrots
Sports

4. (TCO 7) Which of the following statements are true?
Interfaces contain a list of method signatures.
Interfaces contain constants, abstract methods and fully implemented constructors.
Static Interface objects are instantiated using the new keyword just like regular classes.
An Interface represents a specific type of class inheritance.

5. (TCO 7) Abstract classes may contain which of the following?
A. Abstract methods
B. Non-abstract methods
C. Constants
A and B
A and C
B and C
A, B, and C

6. (TCO 7) In terms of object-oriented programming, rules for the use of an application programming interface or framework can be enforced through the use of a(n) _____.
contract
inheritance hierarchy
has-a relationship
object constructed with a multi-arg constructor
All of the above

7. (TCO 8) Data/information hiding and encapsulation improves construction and maintenance because:
Adding additional details is isolated to a single class.
Program bugs are isolated to a single class.
Programming to an interface makes the code more logical.
All of the above
None of the above

8. (TCO 8) What are some of the characteristics of “self-documenting” code?
Detailed comments, addressing all aspects of the code
Deep levels of nesting to ensure all situations are addressed
Straightforward algorithms
All of the above
None of the above

9. (TCO 9) Which of the following allow a programmer to reduce the complexity of an object-oriented program?
Create each class in a separate file
Using packages as a container for logically related items
Using packages to create global types
All of the above
None of the above

10. (TCO 2) Given a private attribute called weight, which of the following are proper Java implementations for a getter and a setter?
void getWeight(){return weight;}
void setWeight (int weight){this.weight = weight;}
int getWeight (){return weight;}
int setWeight (int weight){return weight;}
int getWeight (){this.weight = weight;}
void setWeight (int weight){return weight;}
int getWeight (){return weight;}
void setWeight (int weight){this.weight = weight;}

11. (TCO 7) Which of the following declares an abstract method in an abstract Java class?
public abstract calculateTip();
public abstract double calculateTip();
public double abstract calculateTip();
public double calculateTip() {}

12. (TCO 1) Assuming a class definition of a Pet, how many objects are created in the code below?
Pet newObject;
Pet newPetObject = new Pet();
Pet newPet = new Pet(“Fido”);
newObject = newPetObject;
newObject.petName = newPet.petName;
1
2
3
4
Essay Questions
1. (TCO 2) Given the following program description,
identify the required classes/objects necessary to achieve the program requirements;
briefly describe any relationships that might exist between your classes; and
briefly describe the overall hierarchy of your proposed classes.

Program Description – You have been asked to create a program designed to ring up orders in any store. The program must create a new electronic “shopping cart” with a unique id that can be associated with a specific customer. The shopping cart must accept any number of items including both taxable and non-taxable items, it should calculate the tax on the order and display the final price. (Points : 18)

2. (TCO 7) Briefly describe what an Interface is and how it can be used in an object-oriented program. Provide example pseudocode showing how an iCountry Interface might be constructed. (Points : 18)

3. (TCO 4) Consider the class Apple. Given your knowledge of some common components of apples

– show a class hierarchy in which the class Apple inherits from other classes, which, in turn, can also be inherited from yet other classes;
– discuss inheritance from class Apple for other closely related derived classes; and
– discuss the common components of class Apple. (Points : 18)

4. (TCO 3) How does the “is-a” relationship relate to inheritance? Give an example of such a relationship. (Points : 18)
5. (TCO 2) Yacht is a class that is derived from the Boat class. The Boat class has two data members that represent weight and color. The Yacht class has a data member that represents the size of the yacht. Each of the two classes have a member function named printData(). Write the class descriptions for each of the two classes with the appropriate constructors destructors and access specifiers using appropriate naming conventions and data types. Do not write the function implementation. (Points : 18)
6. (TCO 2) Define and implement the overloaded constructors that support the following test function for a Student class. The data members for the Student class are age, name, and DSI. Data member age is an integer number, name and DSI are strings.
public static void main(String args)
{
//s1 will take all default value
Student s1();
//s2 will take all supplied values
Student s2(23, “Student Joe”, “D12345678”);
//s3 will take supplied age. name and DSI will take default value
Student s3(25);
// s4 will take supplied age and name. DSI will take default value
Student s4(28, “James Bond”);
//s5 will take the same value as s2
Student s5=s2;

//the rest of the code
} (Points : 18)
7. (TCO 8) If you were a manager and wanted to address best practices in choosing appropriate names for attributes and their associated accessor/mutator properties, what would you say? (Points : 22)