Professional Documents
Culture Documents
Starting Out With Java From Control Structures Through Objects 7th Edition Gaddis Test Bank
Starting Out With Java From Control Structures Through Objects 7th Edition Gaddis Test Bank
TRUE/FALSE
1. The key word this is the name of a reference variable that an object can use to refer to itself.
ANS: T
2. The key word this is the name of a reference variable that is available to all static methods.
ANS: F
3. The names of the enum constants in an enumerated data type must be enclosed in quotation marks.
ANS: F
ANS: T
ANS: T
6. An instance of a class does not have to exist in order for values to be stored in a class's static fields.
ANS: T
7. A class's static methods do not operate on the fields that belong to any instance of the class.
ANS: T
ANS: F
9. If a class has a method named finalize, it is called automatically just before an instance of the class
is destroyed by the garbage collector.
ANS: T
10. If a class has a method named finalize, it is called automatically just before a data member that has
been identified as final of the class is destroyed by the garbage collector.
ANS: F
11. If you write a toString method for a class, Java will automatically call the method any time you
concatenate an object of the class with a string.
ANS: T
12. When an object is passed as an argument, it is actually a reference to the object that is passed.
ANS: T
13. Both instance fields and instance methods are associated with a specific instance of a class, and they
cannot be used until an instance of the class is created.
ANS: T
14. A single copy of a class's static field is shared by all instances of the class.
ANS: T
15. When an object reference is passed to a method, the method may change the values in the object.
ANS: T
16. If you write a toString method to display the contents of an object, object1, for a class,
Class1, then the following two statements are equivalent:
System.out.println(object1);
System.out.println(object1.toString());
ANS: T
MULTIPLE CHOICE
5. When you make a copy of the aggregate object and of the objects that it references, __________.
a. you are performing a shallow copy
b. you are performing a nested copy
c. you are performing a deep copy
d. a compiler error will occur
ANS: C
8. The "has a" relationship is sometimes called a(n) __________ because one object is part of a greater
whole.
a. enterprise c. mutual relationship
b. possession d. whole-part relationship
ANS: D
9. The whole-part relationship created by object aggregation is more often called a(n) __________
relationship.
a. "has a" c. extra class
b. inner class d. inside class
ANS: A
10. The JVM periodically performs the __________ process to remove unreferenced objects from
memory.
a. memory shuffling c. garbage collection
b. system restore d. memory sweeping
ANS: C
11. CRC stands for __________.
a. Class, Recyclability, Collaborations c. Class, Responsibilities, Collaborations
b. Class, Redundancy, Collections d. Code, Reuse, Constancy
ANS: C
12. Enumerated types have the __________ method which returns the position of an enum constant in the
declaration list.
a. position c. ordinal
b. location d. index
ANS: C
13. Java automatically stores a __________ value in all uninitialized static member variables.
a. 0 b. -1 c. null d. false
ANS: A
14. You cannot use the fully-qualified name of an enum constant for ___________.
a. a case expression c. a boolean expression
b. an argument to a method d. Any of these
ANS: A
17. When a method's return type is a class, what is actually returned to the calling program?
a. an object of that class
b. a reference to an object of that class
c. the values in the object that the method accessed
d. nothing - the return type is simply for documentation in this situation
ANS: B
19. You cannot use the == operator to compare the contents of __________.
a. objects c. integers
b. strings d. Boolean values
ANS: A
20. An object's __________ is simply the data that is stored in the object's fields at any given moment.
a. value c. record
b. assessment d. state
ANS: D
21. A static field is created by placing the key word static __________.
a. after the access specifier and the field's data type
b. after the access specifier and before the field's data type
c. after the field name
d. in brackets, before the field's data type
ANS: B
22. A declaration for an enumerated type begins with the __________ key word.
a. enumerated c. ENUM
b. enum type d. enum
ANS: D
27. If you attempt to perform an operation with a null reference variable __________.
a. the resulting operation will always be zero
b. the results will be unpredictable
c. the program will terminate
d. Java will create an object to reference the variable
ANS: C
28. If object1 and object2 are objects of the same class, to make object2 a copy of object1
__________.
a. write a method for the class that will make a field by field copy of object1 data
members into object2 data members
b. use the copy method that is a part of the Java language
c. use the default constructor to create object2 with object1 data members
d. use an assignment statement to make object2 a copy of object1
ANS: A
29. If you have defined a class, SavingsAccount, with a public static method,
getNumberOfAccounts, and created a SavingsAccount object referenced by the variable
account20, which of the following will call the getNumberOfAccounts method?
a. account20.getNumberOfAccounts();
b. SavingsAccount.getNumberOfAccounts();
c. getNumberOfAccounts();
d. SavingsAccount.account20.getNumberOfAccounts();
ANS: B
30. If you have defined a class, SavingsAccount, with a public static data member named
numberOfAccounts, and created a SavingsAccount object referenced by the variable
account20, which of the following will assign numberOfAccounts to numAccounts?
a. numAccounts = account20.numAccounts;
b. numAccounts = numOfAccounts;
c. numAccounts = SavingsAccount.numberOfAccounts;
d. numAccounts = account20;
ANS: C
31. Assume the class BankAccount has been created and the following statement correctly creates an
instance of the class.
BankAccount account = new BankAccount(5000.00);
What is true about the following statement?
System.out.println(account);
a. A runtime error will occur.
b. The method will display unreadable binary data on the screen.
c. The account object's toString method will be implicitly called.
d. A compiler error will occur.
ANS: C
34. If the following is from the method section of a UML diagram, which of the statements below is true?
+ equals(object2:Stock) : boolean
a. This is a public method that accepts a Stock object as its argument and returns a
boolean value.
b. This is a public method that returns a reference to a String object.
c. This is a private method that receives two objects from the Stock class and returns a
boolean value.
d. This is a private method that returns a boolean value.
ANS: A
35. If the following is from the method section of a UML diagram, which of the statements below is true?
+ add(object2:Stock) : Stock
a. This is a private method named add that accepts and returns objects of the Stock class.
b. This is a private method named Stock that adds two objects.
c. This is a public method named add that accepts and returns references to objects in the
Stock class.
d. This is a public method named Stock that adds two objects.
ANS: C
36. Given the following method header, what will be returned from the method?
public Rectangle getRectangle()
a. the address of an object of the Rectangle class
b. the values stored in the data members of the Rectangle object
c. a graph of a rectangle
d. an object of the class Rectangle
ANS: A