java quiz

1. (TCO 1) Object-oriented programming generally focuses on _____. (Points : 5)
A. separating the interface from the implementation.
B. client side access to implementation details.
C. information hiding.
D. reuse of code.
All of the above
Only A and B
Only A, C, and DQuestion 2. 2. (TCO 2) Which of the following components of a class definition have a return type? (Points : 5)
Constructors
Overloaded constructors
All of the above
None of the aboveQuestion 3. 3. (TCO 5) Which of the following method pairs are not examples of method overloading? (Points : 5)
A. public void dance()
public int dance(int x)
B. public int walk(int x, int y)
public void walk(int x, int y, int z)
C. public int jump(int x, int y)
public void jump(int y, int x)
All of the above
Only A and BQuestion 4. 4. (TCO 1) Which of the following statements is/are true? (Points : 5)
You can create sub-classes, but not sub-objects.
Abstraction is the basic concept of the object-oriented paradigm.
Objects are created during program execution and eventually destroyed.
All of the aboveQuestion 5. 5. (TCO 1) Which of the following would be the most appropriate choice for a method in a Cube class? (Points : 5)volume
area
radius
calculateDiameterQuestion 6. 6. (TCO 2) Which of the following statements is/are true? (Points : 5)
A. The state of an object must be public, for easier modification.
B. A static method of a class can access non-static members of the class directly.
C. A constructor is automatically created for you if you do not define one.
None of the above
Only B and CQuestion 7. 7. (TCO 2) A black box is a term used to describe a system that can be understood solely based on its inputs, a description of its processing and the resulting _____. (Points : 5)
outputs
inherited processes
attributes
accessorsQuestion 8. 8. (TCO 2) A class is designed with three public attributes: attributeOne, attributeTwo, and attributeThree. attributeOne is an integer data type, attributeTwo is a double data type and attributeThree is a string data type. Which pseudocode representation(s) of getters would be appropriate for this class? (Points : 5)
A. int getAttributeOne()
{
return attributeOne
}
B. string getAttributeTwo()
{
return attributeTwo
}
C. int getAttributeThree(int newAttributeThree)
{
attributeThree = newAttributeThree
}
D. void getAttributeTwo()
{
return attributeOne
}
Both A and D
None of the aboveQuestion 9. 9. (TCO 2) You have been tasked to create an EntertainmentSystem 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? (Points : 5)
Declare a single no-arg constructor in order to prevent outside entities from initializing the state of a new EntertainmentSystem object.
Combine attributes and behaviors specific to an EntertainmentSystem together into one cohesive unit.
Declare the class as static so that only one instance of an EntertainmentSystem can be used at a time.
Declare the class as private.
All of the aboveQuestion 10. 10. (TCO 4) Select the false statement regarding inheritance.
(Points : 5)
A child class can have more functionality than parent class.
A child class can itself be parent class.
Common functionality needs to be designed in the parent class.
Parent classes are usually more specific than child classes.Question 11. 11. (TCO 4) There are two classes: class GeometricObject and class Cylinder. Which one is the base class and which one is the derived class?
(Points : 5)
class GeometricObject is the derived class from Cylinder.
They have nothing in common and therefore have no relationships.
class Cylinder is the base class.
class Cylinder is derived from GeometricObject.Question 12. 12. (TCO 3) Which of the following might be potential class(es) in an application?
(Points : 5)
Address
Item
Credit
All of the above
None of the above

Question 1. 1. (TCO 3) Which of the following correctly describes the steps taken to develop classes using the object-oriented design process, after we develop a prototype for the user interface?
(Points : 5)
Identifying class - determining the class responsibilities - determining class interaction - creating UML diagram Determining the class responsibilities - identifying class - determining class interaction -
creating UML diagram
Determining the class responsibilities - determining class interaction - identifying class -
creating UML diagram
Creating UML diagram - identifying class - determining the class responsibilities - determining class interactionQuestion 2. 2. (TCO 4) In what type(s) of situation(s) would it be best to make a new derived class from a base class?
(Points : 5)
When your old class is a general form of what your new class should be
When you need to create a specialized class from an existing class
None of the above
All of the aboveQuestion 3. 3. (TCO 6) _____ is the ability to combine data and operations on that data into a single unit.
(Points : 5)
Inheritance
Encapsulation
Polymorphism
CompositionQuestion 4. 4. (TCO 7) Which of the following statements are false? (Points : 5)
Interfaces specify a contract that must be respected by programmers implementing the interface.
Interfaces specify one or more method signatures and at least one implementation.
Interfaces can be used in some object-oriented languages to implement a form of multiple inheritance.
Interfaces are often implemented by regular classes
Question 5. 5. (TCO 7) Which of the following statements is/are false? (Points : 5)
Abstract methods may or may not contain a method body
Abstract methods may be defined in an abstract class, a regular class or an interface
Abstract methods do not specify a return type
None of the above
All of the above
Question 6. 6. (TCO 7) When developing an object-oriented application, developers are required to comply with specific _____ or rules defined in a framework. (Points : 5)
programming styles
object hierarchies
instantiated classes
contracts
None of the above
Question 7. 7. (TCO 8) Data/information hiding and encapsulation improves construction and maintenance because:
(Points : 5)
Program bugs are isolated to a single class.
Coupling is increased.
Programming to an interface makes the code and design difficult.
All of the above
None of the above
Question 8. 8. (TCO 8) What are some of the characteristics of "self-documenting" code?
(Points : 5)
Logical identifier names
Value-adding comments
Straightforward algorithms
All of the above
None of the above
Question 9. 9. (TCO 9) Which of the following allow a programmer to reduce the complexity of an object-oriented program?
(Points : 5)
A. Create each class in a separate file
B. Using packages as a container for logically related items
Both A and B
None of the above
Question 10. 10. (TCO 7) Which of the following declares an abstract method in an abstract Java class? (Points : 5)
public void drive() {}
public abstract void drive() {}
public abstract drive();
public abstract void drive();
Question 11. 11. (TCO 4) Given the following class implementation, which of the following class definitions correctly inherits from ClassB?
public class ClassB {
private int intVariable;
protected String stringVariable;
public double doubleVariable;
void greatMethod(){
System.out.println("ClassB greatMethod");
}
private void greatPrivateMethod(){
System.out.println("ClassB greatPrivateMethod");
}
public void greatPublicMethod(){
System.out.println("ClassB greatPublicMethod");
}
} (Points : 5)
ClassB implements ClassD
ClassD implements ClassB
ClassB extends ClassD
ClassD extends ClassD
None of the methods will be inherited
Question 12. 12. (TCO 7) Which of the following is a proper declaration of an abstract method? (Points : 5)
public abstract eat();
public abstract void eat();
public void eat();
public void abstract eat();
All of the above
None of the above

1. (TCO 2) Provide an example, which shows the distinction between Encapsulation and Data/Information Hiding in object-oriented programming.
2. (TCO 2) Keeping in mind all object-oriented programming best practices, create a class for a Chair, with the following specifications:1. Specify two data members2. Default Constructor3. Overloaded Constructor which takes both data member values as input.4. Generate a unique identification number for each object instantiated from this class. Use a static data member to keep track of the identification number last assigned to an object so that duplications will not occur.5. Show a statement which instantiates an object of this class using the overloaded constructor.You do not need to provide any accessor/mutator methods or other methods.
3. 3. (TCO 2) Given the following list of classes, attributes and methods,
- identify which items are classes, which items are attributes and which items are methods;
- identify which class each attribute and method belongs to; and
- suggest a class hierarchy given your list of classes.
*Note - no particular capitalization scheme is used in the list below to differentiate between classes, methods and attributes.
Brew, DecreaseTemperature, Manufacturer, MinCups, Price, TurnOff, Oven, MaxTemperature, BrewStrength, NumberOfRacks, IncreaseTemperature, TurnOn, StartTimer, CoffeeMaker, KitchenAppliance, MaxCups, YearBuilt, Grind (Points : 18
)4) Briefly describe what an interface is and how it can be used in an object-oriented program. Provide example pseudocode showing how an iAnimal Interface might be constructed.
5) What is an abstract class? What is an interface? How are abstract classes and Interfaces the same? How are they different? Finally, how do you use abstract methods defined inside an abstract class or Interface? (Points : 18)
6) (TCO 2) Define and implement the overloaded constructors that support the following test function for a Cube class. The data member for the Cube class is side which holds an integer.
public static void main(String args[])
{
//c1 will take all default values
Cube c1();
//c2 will take supplied side value
Cube c2(6);
//c3 will take the same value of c2
Cube c3=c2;
//the rest of the code
}
7) (TCO 7) Create a Java Interface called Auto that contains two method declarations: moveForward and turnRight. Create a Java class called FordTruck that implements the Auto interface and includes two attributes: model and yearBuilt. Finally, show an instantiation of the FordTruck class that sets the FordTruck's model to F550 and yearBuilt to 2002. (Points : 22)


Powered by